English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP mktime() Function Usage and Example

PHP Date & Time Function Manual

The mktime() function gets a Unix timestamp of a date

Definition and Usage

mktimeThe function accepts hours, minutes, seconds, month, day, and year as parameters (representing the date) and returns the Unix timestamp for the given date. If no parameters are passed to this method, it will return the current timestamp.

Syntax

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

Parameter

Serial NumberParameters and Description
1

hours(Required)

This is an integer value representing the number of hours from the start of the day.

2

minute(Required)

This is an integer value representing the number of hours from the start of the hour.

3

seconds(Optional)

This is an integer value representing the number of seconds from the start of the minute.

4

month(Required)

This is an integer value representing the month of the year, it should be between1to12between.

5

day(Required)

This is the integer value representing the date, it should be less than the number of days allowed in the given month.

6

year(Required)

This is the integer value representing the year of the date, it should be between1to32767between.

7

is_dst(Required)

If the time is during daylight saving time (DST), you can set this parameter to1; If it is not daylight saving time (DST), you can set this parameter to-1(default)

Return Value

The PHP mktime() function returns a Unix timestamp representing the given date. If it fails, this function returns a boolean valuefalse.

PHP Version

This function was originally introduced in PHP 4introduced in version .0 and can be used in all higher versions.

Online Example

The following examples demonstratemktimeFunction Usage-

<?php
   $timestamp = mktime();   
   print($timestamp);
?>
Test to see‹/›

Output Result

1589308340

Online Example

Now, let's call the above method by passing all the necessary parameters-

<?php
   $timestamp = mktime(7, 36, 45, 06, 25, 2017);   
   print($timestamp);
?>
Test to see‹/›

Output Result

1498376205

Online Example

<?php
   $lastday = mktime(0, 0, 0, 3, 0, 2010);
   echo strftime("2010year2The last day of the month is: %d\n   
   $lastday = mktime(0, 0, 0, 4, -31, 2010);
   echo strftime("2010year2The last day of the month is: %d, $lastday);
?>
Test to see‹/›

This produces the following result-

2010year2The last day of the month is: 28
2010year2The last day of the month is: 28