$searchTime = date('Y-m-d H:i:s', (time() + strtotime("+5 day")));

printing searchTime returns 2058-02-04 05:26:12. Any Idea why?

time() returns the correct time so it's not the problem.

有帮助吗?

解决方案

You're effectively adding the timestamp of "today" (time()) to the timestamp of "today + 5 days" (strtotime('+5 day')) which, given that the timestamp of "today" is ~40+ years from 0, that makes sense. You can read about Unix time here for a more in-depth explanation regarding the "starting time".

To fix this, remove the time() + portion and just use the return value of strtotime('+5 day'):

$searchTime = date('Y-m-d H:i:s', strtotime("+5 day"));

其他提示

Because you're adding the time right now, to the time 5 days from now.

echo date('Y-m-d H:i:s', strtotime("+5 day"));
// 2014-01-24 15:52:04

Try

 $searchTime = date('Y-m-d H:i:s', strtotime("+5 day"));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top