The built-in PHP mktime() function accepts hours, minutes, seconds, month, day, year as parameters (which represents a date) and returns the Unix timestamp for the given date. If you have not yet passed any parameters to this function, then it returns the current timestamp.
Syntax
mktime($hour, $minute, $second, $month, $day,$ year, $is_dst)
Parameter Details
Sr.No | Parameter & Description |
---|---|
1 | hours(Mandatory) This is an integer value representing the number of hours of the day, from its start. |
2 | minute(Mandatory) This is an integer value representing the number of minutes of an hours, from its start. |
3 | seconds(Optional) This is an integer value representing the number seconds of a minute, from its start. |
4 | month(Mandatory) This is an integer value representing the month of an year, which should be between 1 and 12. |
5 | day(Mandatory) This is an integer value representing the day of a date, it should be below the allowed number of days in the given month. |
6 | year(Mandatory) This is an integer value representing the year of a date, it should be between 1 and 32767. |
7 | is_dst(Mandatory) This parameter can be set to 1 if the time is during daylight savings time (DST), 0 if it is not, or -1 (the default) |
Return Value
PHP Version
Example1
<?php $timestamp = mktime(); print($timestamp); ?>
Output
1606069880
Example2
<?php $timestamp = mktime(7, 36, 45, 06, 25, 2017); print($timestamp); ?>
Output
1498376205
Example3
<?php $lastday = mktime(0, 0, 0, 3, 0, 2010); echo strftime("Last day in Feb 2010 is: %dn", $lastday); $lastday = mktime(0, 0, 0, 4, -31, 2010); echo strftime("Last day in Feb 2010 is: %d", $lastday); ?>
Output
Last day in Feb 2010 is: 28nLast day in Feb 2010 is: 28
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.