PHP mktime() Function
In this chapter you will learn:
- Definition for PHP mktime() Function
- Syntax for PHP mktime() Function
- Parameter for PHP mktime() Function
- Return value for PHP mktime() Function
- Example - use PHP mktime() Function to create an integer Unix timestamp
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.
Parameter | Is Required | Description |
---|---|---|
hour | Optional. | hour value |
minute | Optional. | minute value |
second | Optional. | second value |
month | Optional. | month value |
day | Optional. | day value |
year | Optional. | 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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP strftime() Function
- Syntax for PHP strftime() Function
- Parameter for PHP strftime() Function
- Format for PHP strftime() Function
- Return value for PHP strftime() Function
- Example - Format local date and time according to locale settings
Home » PHP Tutorial » PHP Date Functions