开发者

strtotime calculates wrong when moving over to linux (webhost) from windows (localhost)

I've some problem with make a simple PHP function to work on my webspace meanwhile it works like expected at my localhost server.

The problem is the following calculation:

echo $Formated = date("Ymd",strtotime("last day of next month开发者_高级运维"));

This script dosen't seem to work b/c i simply gets the default date 19691231 instead of the correct one 20110630 when running it on my server.

I use windows (XAMP) as my localhost server so i guess there must be some form of problem that lies within the two platforms way of handling it?


strtotime is notoriously problematic going cross-version, so I'd recommend a vast simplification. You can use the 't' character in the date format to represent the last day of the month, then reduce your strtotime call to simply return some timestamp for the next month.

echo $Formated = date("Ymt", strtotime("next month"));


dont use of if month name is not given

try with

 date('m/d/y', strtotime('last day next month')); 

 OR

 date('m/d/y', strtotime('last day of march'));  // give the month name with of

Reference


Forget Migration and Deployment, in fact strtime is not reliable. Navigate PHP's official site: Check the strtotime manual, especially this comment.

If you have a MySQL connection available, SELECT DATE_ADD( '2011-05-31', INTERVAL 1 MONTH ) would be less redundant since the (correct) functionality is already implemented without you having to implement it yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜