Share on Google+Share on Google+


The following example of mkdate function is used for returning Unix timestamp.

PHP mktime() Function

The mktime() returns the Unix timestamp for a date that contains the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified. The arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time. If the arguments are invalid, the function returns false in PHP 5.1 version and thereafter while in earlier version, it returned -1.



Parameter & Description of mktime() Function PHP

hour - Optional. Specifies the number of the hour.

minute - Optional. Specifies the number of the minute.

second - Optional. Specifies the second.

month - Optional. Specifies the numerical month

day - Optional. Specifies the number of the day

year - Optional. Specifies the number of year. The valid range for year is on some systems between 1901 and 2038. However this limitation is overcome in PHP 5

is_dst - Optional. Set this parameter to 1 if the time is during daylight savings time (DST), 0 if it is not, or -1 (the default) if it is unknown. If it's unknown, PHP tries to find out itself (which may cause unexpected results). Note: This parameter became deprecated in PHP 5. The new timezone handling features should be used instead.

Example of mktime() Function PHP:

The mktime() function is useful for doing date arithmetic and validation. It will automatically calculate the correct value for out-of-range input:


echo(date("M-d-Y",mktime(0,0,0,12,36,2001))."<br />");

echo(date("M-d-Y",mktime(0,0,0,14,1,2001))."<br />");

echo(date("M-d-Y",mktime(0,0,0,1,1,2001))."<br />");

echo(date("M-d-Y",mktime(0,0,0,1,1,99))."<br />");



Posted on: August 29, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null