Computer >> Computer tutorials >  >> Programming >> PHP

mktime() function in PHP


The mktime() function returns the Unix timestamp for a date. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.

Syntax

mktime(hour,minute,second,month,day,year,is_dst);

Parameters

  • hour − Specifies the hour.

  • minute − Specifies the minute

  • second − Specifies the second

  • month − Specifies the month

  • day − Specifies the day

  • year − Specifies the year

  • is_dst − Parameters always represent a GMT date so is_dst doesn't influence the result.

Return

The mktime() function returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.

Example

The following is an example −

<?php
   echo "March 20, 2017 was on " . date("l", mktime(0, 0, 0, 03, 20, 2017));
?>

Output

The following is the output −

March 20, 2017 was on Monday

Example

Let us see another example −

<?php
   echo date("M-d-Y",mktime(0,0,0,22,9,2018)) . "<br>";
?>

Output

The following is the output −

Oct-09-2019