开发者

PHP date difference extremly hard to accomplish

I have to get back dates just subtracting days from the current date and time.

Let suppose current date is May 1, 2011

after subtracting 30 days

April 1, 2011

How to accomplish开发者_如何学JAVA this in PHP? Please help


$unixtime = strtotime("May 1, 2011 -30 days");
$human_readable = date('F j, Y', $unixtime);


Elaborating on Emil's answer. You can one-line it like so:

$thirty_days_ago = date('F j, Y', strtotime('-30 days'));

If you leave out the "May 1, 2011" part in strtotime(), you'll get 30 days ago from whatever the current date is.

Also, you've got a number of options for formatting in the docs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜