w3resource

PHP: strtotime() function

Description

The strtotime() function is used to convert an english textual datetime description to a UNIX timestamp.

Version:

(PHP 4 and above)

Syntax:

strtotime (dttime_string, ts_now)

Parameters:

Name Description Required / Optional Type
dttime_string The string to parse. Required String
ts_now The timestamp used to calculate the returned value. Optional Integer

Return value:

A timestamp on success, FALSE otherwise.
Previous to PHP 5.1.0, this function would return -1 on failure.

Value Type: Integer.

Example:

<?php
echo strtotime('now').'<br>';
echo strtotime('10 January 2000').'<br>';
echo strtotime('+1 day').'<br>';
echo strtotime('+1 week').'<br>';
echo strtotime('+2 days 6 hours 2 seconds').'<br>';
echo strtotime('next Monday').'<br>';
echo strtotime('last Saturday').'<br>';
?>

Sample Output:

1507032423
947462400
1507118823
1507637223
1507226825
1507507200
1506729600

Note : Since the time/date is not static, therefore the output may vary.

View the example in the browser

See also

PHP Function Reference

Previous: strptime
Next: time



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/php/function-reference/strtotime.php