Home >>PHP Date Time Functions >PHP mktime() Function
PHP mktime() function is used to return the Unix timestamp for a given input date. It returns a long integer containing the number of seconds between the Unix Epoch and the time given. It accepts seven parameters $hour, $minute, $second, $month, $day, $year and $is_dst. It returns an integer Unix timestamp as output on success and False in the case of error.
Syntax:
mktime( $hour, $minute, $second, $month, $day, $year, $is_dst);
Parameter | Description |
---|---|
hour | This is an optional parameter. This parameter defines the hour. |
minute | This is an optional parameter. This parameter defines minute. |
second | This is an optional parameter. This parameter defines the second. |
month | This is an optional parameter. This parameter defines the month. |
day | This is an optional parameter. This parameter defines the day. |
year | This is an optional parameter. This parameter defines the year. |
is_dst | This is an optional parameter. This parameter is removed in PHP 7.0. |
Here is an example of mktime() function in PHP:
<html> <body> <?php echo date("d-m-Y H:i:s", mktime(13,22,45,06,10,2020)); ?> </body> </html>
Example 2:
<html> <body> <?php echo date("d-m-Y H:i:s")."<br><br>"; // current date time. echo date("d-m-Y H:i:s", mktime(13,22,45,6,10,2020))."<br>"; echo date("d-m-Y", mktime(0,0,0,8,15,1947))."<br>"; echo date("dS M, Y ", mktime(0,0,0,2,14,2020))."<br>"; echo date("d-m-Y (l)", mktime(13,22,45,06,10,2050))."<br>"; ?> </body> </html>