Click to See Complete Forum and Search --> : Date Display


Jimbo2150
05-23-2003, 03:37 PM
How do I display a message within... say... 5 days of the recorded date.

I have a table with:
a_date - ACTUAL EVENT's DATE
s_date - EVENT's START DATE
e_date - EVENT's END DATE
...as well as title and message to display.

How do I take a_date and display for 10 days (5 days before, 5 days after)?
I already have a code going but I run into the problem of getting to the end of a month. It keeps going... May 32?
Is there a way to add days and keep it rotating (if it reaches the end of a month, cycle to the next month)?

koeniepoenie
05-25-2003, 06:24 AM
you can maybe show what you already have got.. so maybe we can take a look :)
and see what we can do
grtz Koen

Quasibobo
05-26-2003, 05:00 PM
This should work:

$yesterday = mktime (0, 0, 0, date("m"), date ("d") - 1, date("Y"));
$yesterday = date ("Ymd", $yesterday);

I hope you get the idea with this example. 32 Mai won't happen with this script.....

Quasibobo

pyro
05-26-2003, 05:51 PM
This should be close to what you are looking for. It will take the day in $a_date and check for 5 days prior to it, and 5 days after it. If it falls within that date, it will print a message. This is assumbing the date is in a MM-DD-YYYY format.

<?PHP

$today = time();
$days = "432000"; # 5 days in seconds # 1 day = 86400 seconds

$a_date = "05-31-2003"; #actual date

$d = split("-",$a_date);

$a_date_seconds = mktime(0,0,0,$d[0],$d[1],$d[2]);

$s_date = $a_date_seconds - $days; # 5 days before $a_date
$e_date = $a_date_seconds + $days; # 5 days after $a_date


if ($today > $s_date && $today < $e_date) {
echo ("The date is between the range");
}
else {
echo ("The date is outside the range");
}

?>