Subtract 1 day with PHP

后端 未结 10 782
我在风中等你
我在风中等你 2020-11-28 06:52

I\'m trying to take a date object that\'s coming out of my Drupal CMS, subtract one day and print out both dates. Here\'s what I have

$date_raw = $messageno         


        
10条回答
  •  感动是毒
    2020-11-28 07:16

    How about this: convert it to a unix timestamp first, subtract 60*60*24 (exactly one day in seconds), and then grab the date from that.

    $newDate = strtotime($date_raw) - 60*60*24;
    echo date('Y-m-d',$newDate);
    

    Note: as apokryfos has pointed out, this would technically be thrown off by daylight savings time changes where there would be a day with either 25 or 23 hours

提交回复
热议问题