Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

mktime()

Example

Returns the Unix timestamp for a specified date and then use it to determine the day of that date.

<?php
// Prints: October 3, 1975 was on a Friday
echo “Oct 3, 1975 was on a “.date(“l”, mktime(0,0,0,10,3,1975));
?>

Definition and Usage

The mktime() function returns the Unix timestamp for a specified date.

Tip: This function is similar to gmmktime(), except that the parameters represent a local date rather than a GMT date.

Syntax

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

Parameter Values

 

Parameter

Description

hour

Optional. Specifies the hour.

minute

Optional. Specifies the minute.

second

Optional. Specifies the second.

month

Optional. Specifies the month.

day

Optional. Specifies the day.

year

Optional. Specifies the year.

is_dst

Optional. Set this parameter to 1 if the time is during daylight saving time (DST), 0 if it is not, or -1 (the default) if unknown. If set to -1, PHP attempts to determine it automatically, which may lead to unexpected results. Note: This parameter was removed in PHP 7.0; use the new timezone handling features instead.

Technical Details

Return Value:

Returns an integer Unix timestamp or FALSE on error.

PHP Version:

4+

PHP Changelog:

  PHP 7.1: The is_dst parameter is removed.

  PHP 5.3.0: Issues an E_DEPRECATED warning if the is_dst parameter is used.

  PHP 5.1: The is_dst parameter was deprecated. If mktime() is called with no arguments, it now triggers an E_STRICT notice. Use the time() function instead.