dc_jt Posted March 20, 2007 Share Posted March 20, 2007 Hi I have a date which is set as 2007-02-01, can easily be changed to different format. However how do I change this date to the day before? In this case 2007-01-31? Thanks Link to comment https://forums.phpfreaks.com/topic/43508-getting-day-before-on-a-set-date-not-todays-date/ Share on other sites More sharing options...
kenrbnsn Posted March 20, 2007 Share Posted March 20, 2007 You can use the strtotime() function: <?php $date = '2007-02-01'; $day_before = date('Y-m-d',strtotime($date . ' -1 day')); echo $day_before; ?> Or you can get the UNIX timestamp of the date and subtract 86,400 (the number of seconds in a day) from it: <?php $date = '2007-02-01'; $day_before = date('Y-m-d',strtotime($date) - 86400); echo $day_before; ?> Ken Link to comment https://forums.phpfreaks.com/topic/43508-getting-day-before-on-a-set-date-not-todays-date/#findComment-211299 Share on other sites More sharing options...
dc_jt Posted March 20, 2007 Author Share Posted March 20, 2007 Thanks a lot Ken Link to comment https://forums.phpfreaks.com/topic/43508-getting-day-before-on-a-set-date-not-todays-date/#findComment-211306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.