php - Modify DateTime on Month short name formatted date string -
i'd use datetime->modify function on date string that's formatted "21 jan 2016". when use datetime->modify , add 1 day, gives me result of 30 apr 2017. know if don't use short month name , use number instead (i.e. 01), work fine work way short month name. possible?
please see code below:
<?php $date = "21 jan 2016"; // date string $newdate = new datetime($date ); $date2 = $newdate->modify('+1 day'); // add 1 day date string echo $date2->format("d-m-y"); ?>
result is:
30-apr-2017
result wanted
22-jan-2016
the problem trying create datetime object non-iso format. that's part not working.
take at: http://php.net/manual/ro/datetime.createfromformat.php
you need have
datetime::createfromformat('d m y', '21 jan 2016');
full example:
$tomorrow = datetime::createfromformat('d m y', '21 jan 2016')->modify('+1 day')->format("d-m-y"); echo($tomorrow);
Comments
Post a Comment