Copyright © tutorialspoint.com

PHP Function strtotime()

previous
Advertisements

Syntax

int strtotime ( string $time [, int $now] );

Definition and Usage

The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp elative to the timestamp given in now, or the current time if none is supplied.

This function will use the TZ environment variable (if available) to calculate the timestamp. Since PHP 5.1.0 there are easier ways to define the timezone that is used across all date/time functions. That process is explained in the date_default_timezone_get() function page.

Paramters

ParameterDescription
timeRequired. Specifies the time string to parse
nowOptional.The timestamp used to calculate the returned value.

Return Value

Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.

Example

Following is the usage of this function:

<?php
$timestamp = strtotime( "February 26, 2007" );
print date( 'Y-m-d', $timestamp );
?>

This will produce following result:

2007-02-26
previous

Copyright © tutorialspoint.com