strtotime()


 

strtotime()

This is the example of strtotime function used for parsing US english textual date into a Unix Timestamp.

This is the example of strtotime function used for parsing US english textual date into a Unix Timestamp.

PHP strtotime() Function

The strtotime() parses a US English textual date or time into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). This function use the TZ environment variable (if available) to calculate the timestamp. 

It is notable that there may be a possible difference of digit format on 32bit systems, e.g if the number of the year is specified in a two digit format, the values between 00-69 are mapped to 2000-2069 and 70-99 to 1970-1999.  

Syntax of strtotime() Function PHP

int strtotime ( string $time [, int $now ] )

Parameter of strtotime() Function PHP

time - This is an essential parameter that specifies the time string to parse
now - Now is optional that is used to specifies the timestamp used to calculate the returned value. If this parameter is omitted, current time is used

Return Value

PHP 5.1.0 and above version returns false on failure while earlier versions returns -1. 

Example of strtotime() Function PHP:

<?php
echo(strtotime("now") . "<br />");
echo(strtotime("25 August 2009") . "<br />");
echo(strtotime("+2 hours") . "<br />");
?>

The output of the code above could be:
1251523244
1251177644
1251530444

Ads