I have a date which is saved in a regular string.
// format = DD-MM-YYYY
$date = "10-12-2011";
How can I get the date-string +1 day so: 11-12-2011?
If you want to do this in PHP: // replace time () with the time stamp you want to add one day to $startDate = time (); date ('Y-m-d H:i:s', strtotime ('+1 day', $startDate)); If you want to add the date in MySQL: -- replace CURRENT_DATE with the date you want to add one day to SELECT DATE_ADD (CURRENT_DATE, INTERVAL 1 DAY);
Code for converting a string to dateTime. <?php. $input = '06/10/2011 19:00:02'; $date = strtotime($input); echo date('d/M/Y h:i:s', $date); ?>.
Comparing two dates in PHP is simple when both the dates are in the same format but the problem arises when both dates are in a different format. Method 1: If the given dates are in the same format then use a simple comparison operator to compare the dates. Example: $date1 = "1998-11-24";
$now = new DateTime (); $date = $now->modify ('+1 day')->format ('Y-m-d H:i:s'); You can use as following.
Similar post
$date = date('d-m-Y', strtotime("+1 day", strtotime("10-12-2011")));
If you're trying to overwrite $date, Aaron's answer works great. But if you need the new day saved into a separate variable as I did, this works:
$date = strtotime('10-12-2011'); // your date
$newDate = date('d-m-Y', strtotime("+1 day", $date)); // day after original date
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