Jump to content

Computing time (subtracting 1 week from variable)


darkhappy

Recommended Posts

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']);
             }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.