I'm trying to setup a simple text database with each item on a new line with the date at the start of the line. Basically when you go to the page it will find the current date and only output the items which are within one week of today. I'll have a big file with all of the items but the first time someone access the page each day it'll output the week's items into a smaller file. Probably not the best way to do this but it doesn't need to be fancy so I'm not getting too into it. Anyways, I'm trying to set up a query for determining if two dates are a week apart and I'm having some trouble.
The easiest option I decided is:
Code: Select all
list($day, $mon, $year) = split('[\/]', $date);
$itemDate= mktime(0,0,0,$mon,$day,$year);
if(date("z", $itemDate)-date("z") < 7)
{
blah blah
}
This works for me but when I get up to december I imagine it will get a bit wonked because z will reset at January 1st. Can I use the "U" option in the date() to determine if there are 604800 seconds (i think I did the math right.. after I remembered there were 60 seconds in a minute and not 30) or less between two dates? I've written this to see what I get and I keep getting an output of 0 and nothing else:
Code: Select all
echo date("U") . " ----- " . date("U", $itemDate) . " -----" . date("U",$itemDate)-date("U") . "<br>";
Any idea what I've screwed up or whether there's a better way? The other idea I figured I could try was to check if the two dates are in the same year then do the query as above, if the item date is in next year (ie. today dec 28, 2006 news item jan 1, 2007) then check that differently and if one item is in 2006 and the other in 2008 then of course it's more than a week apart. I image using the seconds from the epoch seem a cleaner way though.
Thanks