strtotime() function in PHP


The strtotime() function parses an English textual date or time into a Unix timestamp. It returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.

Syntax

strtotime(time, now)

Parameters

  • time  − Specifies the time string to parse.

  • now  − The timestamp used to calculate the returned value.

Return

The strtotime() function returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.

Example

The following is an example −

 Live Demo

<?php
   $timestamp = strtotime( "June 20, 2018" ); print date( 'Y-m-d', $timestamp );
?>

Output

2018-06-20

Example

Let us see another example −

 Live Demo

<?php
   echo(strtotime("now") . "<br>");
   echo(strtotime("10 March 2018") . "<br>");
   echo(strtotime("+10 hours") . "<br>");
?>

Output

1539235161
1520640000
1539271161

Updated on: 24-Dec-2019

137 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements