How do I compare two dates in PHP?

Faith

New member
I am working on my church's website. They have asked me if it would be possible for me to set it up so the church secretary can type events into a text file, and the home page will read it. I have that working, but I would like it to compare dates, and not show old events. I can get it to read the month day and year all as two digit numbers, and I can get it to check the current month day and year, but I can't seem to get the script to compare them. What I tried was something like:
if($eyear >= $year)
{
other code
}
But this seems to always say that the $eyear, which is the event year, is not greater then or equal to the $year, which is the current year. Can anyone help?
 
All you need to do is to compare the date in the SQL query.

Get the beginDate and then the endDate, pass them both to the query so you would have something like this:

$query = "select id, title, description, date from event where date between {$beginDate} and {$endDate}";

With that you would easily retrieve all events that are between those dates.

If you can't do it on an sql query, try to do it in an array. It will be a bit more complex but using mktime for comparison will help out.
 
Back
Top