Log in / create account | Login with OpenID
DocForge
An Open Wiki For Software Developers

PHP/mktime

From DocForge

< PHP

The mktime function of PHP generates a Unix timestamp from date and time components.

Syntax [edit]

 int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] )

The return value is a long integer containing the number of seconds between the Unix epoch (January 1 1970 00:00:00 GMT) and the time specified.

Arguments may be left out in order from right to left. Omitted arguments will be set to the current value according to the local date and time.

The year parameter may be a two or four digit value, with values between 0-69 mapping to 2000-2069 and 70-100 to 1970-2000. As of PHP 5.1.0 the valid range for year is between 1901 and 2038.

Quirks [edit]

The Unix epoch is not returned by passing all zeros as parameters. The year 0 is interpreted as 2000, and 0 month and 0 day roll back each by one value, so the following code...

mktime(0, 0, 0, 0, 0, 0);

... return the Unix timestamp value for November 30, 1999 (time 0). Passing six null parameters has the same result. Therefore, to generate the Unix epoch, the actual date of the epoch must be passed. PHP 5