Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP string date + 1 day equals?

Tags:

date

php

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?

like image 966
sn0ep Avatar asked Dec 10 '11 15:12

sn0ep


People also ask

How do I add one day to a date in PHP?

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);

How to convert a string to datetime in PHP?

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); ?>.

How to compare two dates in PHP?

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";

How to change the date format of $now in PHP?

$now = new DateTime (); $date = $now->modify ('+1 day')->format ('Y-m-d H:i:s'); You can use as following.


2 Answers

Similar post

$date = date('d-m-Y', strtotime("+1 day", strtotime("10-12-2011")));
like image 123
Aaron W. Avatar answered Sep 30 '22 18:09

Aaron W.


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
like image 31
mckenna Avatar answered Sep 30 '22 18:09

mckenna