Are there any differences between using functions time() and mktime() with default parameters to obtain current timestamp?
Asked
Active
Viewed 1.4k times
12
-
`time()` is timezone independent while `mktime()` is not – Yousha Aleayoub Feb 18 '20 at 10:08
1 Answers
18
"As of PHP 5.1, when called with no arguments, mktime() throws an E_STRICT notice: use the time() function instead."
http://php.net/manual/en/function.mktime.php
If you want to use dates/times, I recommend DateTime instead.

Anyone
- 2,814
- 1
- 22
- 27
-
2This is driving me a little crazy. What is the reasoning behind showing this warning? Why is it wrong to call `mktime()` with no parameters? Why have two separate functions at all? Is there any *real* difference between calling `time()` and calling `mktime()` with no parameters? – Travesty3 Apr 28 '17 at 13:49
-
If you would like to get the **current** Unix timestamp use `time()`. If you would like to get the Unix timestamp for a **specific** date/time, then you should use `mktime()`. There may be cases you want to work with a Unix timestamp instead of a formatted Date/Time string. In addition to the DateTime recommendation made by @Anyone, I would like to recommend you use Carbon. Carbon is an extension of DateTime that makes it easier to work with dates and times. – dqfan2012 Jan 24 '19 at 18:13
-
And as of PHP 8.0, calling with no arguments isn't an option at all - it will throw an error. – thelem Mar 28 '23 at 19:54