Home >>PHP Date Time Functions >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 | 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>
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>