-1

Somehow, using strtotime and adding "+1 day" not only adds the day, but also removes 5 minutes.

In the following example I expect '2013-10-02 08:15:00', but get '2013-10-02 08:10:00':

$myDate = '2013-10-01 08:15:00';
$newDate = strtotime($myDate . ' +1 day');
$newDate = strftime("%Y-%m-%d %H:%m:00", $newDate);
debug($newDate);

//'2013-10-02 08:10:00'

BUT - if I use date() instead of strftime(), it works fine

$myDate = '2013-10-01 08:15:00';
$newDate = strtotime($myDate . ' +1 day');
$newDate = date("Y-m-d H:i:s", $newDate);
debug($newDate);

//'2013-10-02 08:15:00'
Dave
  • 28,833
  • 23
  • 113
  • 183
  • On your system only. There must be some other problem, this can't be the full code, is it? – Prashank Nov 03 '13 at 01:22
  • Woops spoke too soon. Happens with strftime function – Prashank Nov 03 '13 at 01:24
  • 3
    lol %m is for month not minute http://php.net/manual/en/function.strftime.php – Prashank Nov 03 '13 at 01:27
  • @Prashank - you're right - I thought it didn't work with both, but it's only w/ `strftime`. That helps at least - I have a workaround. Will still accept any answer that explains why or how to work it w/ strftime. – Dave Nov 03 '13 at 01:28

1 Answers1

3

Needed a capital M instead of m.

Check http://php.net/manual/en/function.strftime.php

$myDate = '2013-10-01 08:15:00';
$newDate = strtotime($myDate . ' +1 day');
$newDate = strftime("%Y-%m-%d %H:%M:00", $newDate);
debug($newDate);
Prashank
  • 796
  • 6
  • 12