strtotime

PHP date() and strtotime() return wrong months on 31st

不羁的心 提交于 2019-11-26 06:41:28
问题 I\'m using date() and strtotime() functions to display the next 3 months in a dropdown list. PHP Code: echo date(\"m/Y\",strtotime(\"+0 months\")); echo date(\"m/Y\",strtotime(\"+1 months\")); echo date(\"m/Y\",strtotime(\"+2 months\")); However, if the script is running when the server date is on 30th or 31st, the next month, which is Feburary, will be displayed as March instead. i.e. the script above is supposed to return 01/2012 02/2012 03/2012 But, instead of that, it actually displays 01

Simplest way to increment a date in PHP?

天涯浪子 提交于 2019-11-26 05:29:28
问题 Say I have a string coming in, \"2007-02-28\" , what\'s the simplest code I could write to turn that into \"2007-03-01\" ? Right now I\'m just using strtotime() , then adding 24*60*60 , then using date() , but just wondering if there is a cleaner, simpler, or more clever way of doing it. 回答1: A clean way is to use strtotime() $date = strtotime("+1 day", strtotime("2007-02-28")); echo date("Y-m-d", $date); Will give you the 2007-03-01 回答2: It's cleaner and simpler to add 86400. :) The high