20

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?

RavatSinh Sisodiya
  • 1,596
  • 1
  • 20
  • 42
sn0ep
  • 3,843
  • 8
  • 39
  • 63
  • possible duplicate of [add day to current date](http://stackoverflow.com/questions/3918646/add-day-to-current-date) –  Dec 10 '11 at 15:46

5 Answers5

63

Similar post

$date = date('d-m-Y', strtotime("+1 day", strtotime("10-12-2011")));
Community
  • 1
  • 1
Aaron W.
  • 9,254
  • 2
  • 34
  • 45
2

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
mckenna
  • 159
  • 1
  • 7
2

You should be using DateTime class for working with dates. Using strtotime() might not be the best choice in the long run.

To add 1 day to the data using DateTime you can use modify() method.

$newDate = date_create_from_format('d-m-Y', $date)
    ->modify('+1 day')
    ->format('d-m-Y');
Dharman
  • 30,962
  • 25
  • 85
  • 135
1

if you want today +$i day

$today = date('Y-m-d');
$tomorrow = strtotime($today." +".$i." day");
devugur
  • 1,339
  • 1
  • 19
  • 25
0

You can either use the date function to piece the date together manually (will obviously require to check for leap years, number of days in current month etc) or get strtotime and convert what you get via the date function parsing the timestamp you got from strtotime as the second argument.

Loki
  • 1