PHP Mktime Function

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

The Mktime() function is an inbuilt function in PHP which is used to return the Unix timestamp for a date. The timestamp returns a long integer containing the number of seconds between the Unix Epoch (January 1, 1970, 00:00:00 GMT) and the time specified.

Syntax:

Int Mktime( $hour, $minute, $second, $month, $day, $year, $is_dst)

parameters

This function has seven optional parameters as mentioned below:

$hour: It is a parameter which specifies the hour.
$minute: It is a parameter which specifies the minute.
$second: It is a parameter which specifies the second.
$month: It is a parameter which specifies the month.
$day: It is a parameter which specifies the day.
$year: It is a parameter which specifies the year.
$is_dst: It is a parameter which can be set to 1 if the time is during daylight savings time (DST), or 0 if it is not.

<?php

// Using mktime() function to know the day
echo "May 21,2022 was on a " . date("l",
mktime(3, 12, 15, 5, 21, 2022));
?>

Output
May 1, 2022 was on a saturday
<?php

// Using mktime() function to know the complete date
echo date("M-d-Y", mktime(0, 0, 0, 5, 21, 2022)) . "<br>";

// Using mktime() function to know the
// complete date for an out-of-range input
echo date("M-d-Y", mktime(0, 0, 0, 6, 21, 2022));

?>

Output

May-05-2022
May-06-2022
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x