darkhappy Posted May 3, 2008 Share Posted May 3, 2008 I am trying to write a foreach loop that will set all the dates in an array back 1 week if flag 'lastweek' is set. The date-modify function seems to make the most sense but i get fatal errors when using it. When I try to convert to a timestamp with date and mktime i get 1970 for the year. for that code i did: date("Y",$value) and it comes out to 1970 every time even though $value (from the foreach loop below) is something like 04-24-2008. any ideas? I have been hacking away at this for hours and am clueless. <?php $week = array($monday, $tuesday, $wednesday, $thursday, $friday, $saturday, $sunday); if($_SESSION['lastweek'] == "1") { foreach($week as $d => $value) { $date = new DateTime($week[$d]); $date->modify("-1 week"); } unset($_SESSION['lastweek']); } ?> Link to comment https://forums.phpfreaks.com/topic/103971-computing-time-subtracting-1-week-from-variable/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.