#### Archived

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

# Dates

## Recommended Posts

I was wondering how I would have a function tell me if a date is before another date or after like
like 3/16/05 before 3/16/06 or 3/12/06 before 4/12/06

thanks

##### Share on other sites
get the date in a variable using the date('Y','M','d') or something like that.

pass the variable and also the current date variable to the function .

Inside the function, jus subtract both variables.

If result>0, the date is greater and otherwise.

This is jus my way of implementing it. you can have a lot other ways.

##### Share on other sites
[code]
{
// date1 is when it expires
\$date2 = date("n/j/Y");
\$date1 = explode("/",\$date1);
\$date2 = explode("/",\$date2);
\$month1 = \$date1[0];
\$day1 = \$date1[1];
\$year1 = \$date1[2];
\$month2 = \$date2[0];
\$day2 = \$date2[1];
\$year2 = \$date2[2];

if (\$year1 < \$year2)
{
// if the expires year is less the current year, toss it out
return false;
}
else if (\$year1 == \$year2)
{
// if the expires year is the same as this year, then we will check month
if (\$month1 > \$month2 && \$year1 == \$year2)
{
// if the current month is before the expired month, and the year is the same, go ahead
return true;
}
else if (\$month1 < \$month2 && \$year1 == \$year2)
{
// if the current month is after the expired month, toss it out
return false;
}
else if (\$month1 == \$month2 && \$year1 == \$year2)
{
// check to see if day is before or after current
if (\$day1 = \$day2 || \$day1 > \$day2)
{
return true;
}
else (\$day1 < \$day2)
{
return false;
}
}
}

}
[/code]
ive got most of it done

##### Share on other sites
for heaven sakes get rid of that code! and use the Unix timestamp and date function.

##### Share on other sites
wait a min, why was I doing regular dates anyway!, almost everything on my site uses the unix time stamp, hahahahahahahaha. thats what midnight does to you