Jump to content

Work out if current date (today) is a week before a given date


Recommended Posts

(continuing from topic title)

So if I set a date of July 7 2011 into my script, hard coded in, I would like the current date to be checked against the hard coded date, and return true if the current date is within a week leading up to the hard coded date.


How could I go about doing this easily?


I've been researching dates in php but I can't seem to work out the best way to achieve what I'm after.




Link to comment
Share on other sites

$then = strtotime('July 7 2011 - 1 week'); // such power at the tip of your fingers
$final = strtotime('July 7 2011');
$now = time();
if($now < $then) {
    echo 'just a little longer..';
} else if($now >= $then && $now < $final) {
    echo 'almost there.. almost there..';
} else if($now == $final) {
    echo 'celebrate good times com\'on!!';
} else {
    echo 'phew, what a PARTYYYY!!!';

Link to comment
Share on other sites


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.