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.
You can use strtotime. $your_date = strtotime("1 day", strtotime("2016-08-24")); $new_date = date("Y-m-d", $your_date);
php $next_due_date = date('05/06/2016', strtotime("+30 days")); echo $next_due_date; ?> But it is returning to "05/06/2016" only!
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With