PHP strtotime

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. <?php  

  2. echo strtotime('now').'<br>';  

  3. echo strtotime('10 January 2000').'<br>';  

  4. echo strtotime('+1 day').'<br>';  

  5. echo strtotime('+1 week').'<br>';  

  6. echo strtotime('+2 days 6 hours 2 seconds').'<br>';  

  7. echo strtotime('next Monday').'<br>';  

  8. echo strtotime('last Saturday').'<br>';  

  9. ?>