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



PHP: Tips of the Day

To use the constant simply use its name:

Example:

if (EARTH_IS_FLAT) {
 print "Earth is flat";
}
print APP_ENV_UPPERCASE; 

Output:


or if you don't know the name of the constant in advance, use the constant function:

// this code is equivalent to the above code
$const1 = "EARTH_IS_FLAT";
$const2 = "APP_ENV_UPPERCASE";
if (constant($const1)) {
 print "Earth is flat";
}
print constant($const2);

Output: