inter Posted February 5, 2008 Share Posted February 5, 2008 Hello all, I have a pretty tough question (for my standards) regarding dates handling in php. I have a date variable called $realdate. Gotten from: $realdatestring = "20" . $year . $month . $daycounter; $realdate = strtotime($realdatestring); I have another variable, a timestamp from a mysql table (onupdate current timestamp), called $edited. So I now have 2 datetime variables right? I would like to check the $edited variable to see if it's value is more recent than the Friday of the week which the $realdate variable is in. EG: if $realdate is 2008-01-01 (a Tuesday), and $edited is 2008-01-06 (the Sunday)... then $edited is after the Friday of the week that $realdate is a part of. Did that make sense? Lol. I'll try to explain it in other words if that's not clear. Thanks for any input or ideas! Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 5, 2008 Share Posted February 5, 2008 Give this a shot <?php $realdate = "2008-01-01"; //We will say this is your timestamp $edited = time(); //convert timestamp to proper format $edited = date("Y-m-d", $edited); //check if $edited is more recent if ($edited > $realdate){ echo "Yes, edited date is more recent"; } else { echo "No, realdate is more recent"; } ?> Quote Link to comment Share on other sites More sharing options...
inter Posted February 5, 2008 Author Share Posted February 5, 2008 Ok, so thats how I check if it's more recent. Thanks for making that clear Do you know if its possible to: I have date variable. I need to find the date of the next Friday that occurs. eg: $date is 2008-01-01 (is a Tuesday), the first following Friday is 2008-01-04. Quote Link to comment Share on other sites More sharing options...
CerealBH Posted February 5, 2008 Share Posted February 5, 2008 <?php $nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs echo 'Now: '. date('Y-m-d') ."\n"; echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n"; // or using strtotime(): echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n"; ?> http://us3.php.net/manual/en/function.time.php Quote Link to comment Share on other sites More sharing options...
inter Posted February 5, 2008 Author Share Posted February 5, 2008 Unfortunately that code only adds a week regardless of the day. Maybe I could just make a table which stores a hard coded amount. Like.. If the day of the week is a Friday, add 0 days. If the day of the week is a Thursday, add 1 day. If the day of the week is a Wednesday, add 2 days. etc. That way it should always find the next friday! The down side is that I dont think I can add times that way, so I couldnt do "5pm Friday", only just "Friday". 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.