Is PHP strtotime function when given format of only m/d/Y guaranteed to return first second of that day?

StackOverflow https://stackoverflow.com/questions/20816712

  •  22-09-2022
  •  | 
  •  

strtotime() returns number of seconds since so and so date. OK. So it's all in seconds. Now, if you give a date format which consists of only day, month and year, what time does it return in terms of seconds. The very first second of the day, the last second or undefined in between? The manual does not provide any guidance and common sense would assume the first second. Why is this significant? It could be when comparing or computing time interval between a fully defined date and a partially defined datetime (one without hours, minutes and seconds).

    strtotime("1/1/2014") 

Is this "guaranteed," as opposed to expected, to return the very first second of the new year?

有帮助吗?

解决方案 2

Yes, it will always return first second of that day:

echo date('Y-m-d H:i:s', strtotime("1/1/2014"));
# 2014-01-01 00:00:00

demo

but to be sure, just enforce time like @Pekka suggested:

echo strtotime("1/1/2014 00:00:00");

其他提示

It will return the time from 00:00:00, e.g. strtotime("1/1/2014"); = strtotime("1/1/2014 00:00:00");

In case you need to be sure, just use:

strtotime("1/1/2014 00:00:00");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top