PHP mktime() Function

Definition

The mktime() function creates Unix timestamp from year, month, day, hour, second in separate variables. It has the following format.

Syntax

PHP mktime() Function has the following syntax.

int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )

Parameter

The parameter are: hour, minute, second, month, day, year, is_dst.

ParameterIs RequiredDescription
hourOptional.hour value
minuteOptional.minute value
secondOptional.second value
monthOptional.month value
dayOptional.day value
yearOptional.year value

Return

PHP mktime() Function returns an integer Unix timestamp. FALSE on error.

Example

Note that the hour should be in 24-hour clock time. So, to pass in 10:30 p.m. on the 21th of June 2012, you would use mktime() like this:


<?PHP
$unixtime = mktime(22, 30, 0, 6, 21, 2012, -1); 
print_r($unixtime);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions