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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
dc_jt Posted March 20, 2007 Author Share Posted March 20, 2007 Thanks a lot Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.