Home >>PHP Date Time Functions >PHP strtotime() Function

PHP strtotime() Function

PHP strtotime() Function

PHP strtotime() function is used to convert a given English textual date-time description to a UNIX timestamp. It accepts a string parameter in $date which represents the English textual date-time description. It returns a timestamp on success and FALSE on failure.

Syntax:

  strtotime($time, $now);

Parameter Values

Parameter Description
time This is a required parameter. This parameter defines a date-time string.
now This is an optional parameter. This parameter defines the timestamp used as a base for the calculation.

Here is an example of strtotime() function in PHP:

<html>
<body>
<?php
echo strtotime("now")."<br>";
echo strtotime("15 August 1947")."<br>";
?>
</body>
</html>
Output:
1580710177
-706320000

Example 2:

<html>
<body>
<?php
echo strtotime("now") . "<br>";
echo strtotime("+10 hours")."<br>";
echo strtotime("-10 hours")."<br>";
echo strtotime("+2 week")."<br>";
echo strtotime("+1 week 5 days 22 seconds")."<br>";
echo strtotime("next Sunday")."<br>";
echo strtotime("last Sunday");
?>
</body>
</html>
Output:
1580710368
1580746368
1580674368
1581919968
1581747190
1581206400
1580601600