PHP – validate UNIX timestamp

Here’s a function in PHP to validate Unix timestamp:

function isValidTimeStamp($strTimestamp) {
    return ((string) (int) $strTimestamp === $strTimestamp) 
        && ($strTimestamp <= PHP_INT_MAX)
        && ($strTimestamp >= ~PHP_INT_MAX);
}
Advertisements
Posted in PHP

One thought on “PHP – validate UNIX timestamp

  1. I think the following would be better, as the input could be an integer as well: (string) $strTimestamp

    function isValidTimeStamp($strTimestamp) {
    return ((string) (int) $strTimestamp === (string) $strTimestamp)
    && ($strTimestamp = ~PHP_INT_MAX);
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s