Date Comparison Question

From: Date: Sat, 27 Jan 2001 06:22:16 +0000
Subject: Date Comparison Question
Groups: php.general 
Request: Send a blank email to php-general+get-36961@lists.php.net to get a copy of this message
I'm fairly new to php and still learning it's nuances, etc. I've created a site - http://www.more-mtb.org - in which I have used several php resources from around the net and some which I have created my self. On the home page of the site I have inserted some code that displays a series of events from a calendar table in a Mysql dB. My idea is to display the 4 upcoming events from today (the current date) including any events that match today's date. The display works great until I get to the end of the month (like now). I have separated the date as three rows in my dB (msg_year, msg_month and msg_day) when I do the query in my code to select the 4 upcoming events I use the following: $query = sprintf("SELECT * FROM calendar_messages WHERE msg_active=1 AND msg_year >= $ThisYear AND msg_month >= $ThisMonth AND msg_day >= $ThisDay ORDER BY msg_year, msg_month, msg_day ASC LIMIT 0, 4 "); The problem is, that even though the first three comparisons are met, the last one , the msg_day is not. At the end of the month the day value is in the high 20s/30s whereas the day value for the next month is in the low digits. And even though my query satisfies the first two (three if you count msg_active) comparisons the fourth is not satisfied and therefore the event is skipped. As soon as the next month starts, then I get 4 events. I know exactly what's wrong, But my non-programmer limitations are coming to light and I have absolutely no clue what to do next or how to proceed. Any direction will be extremely appreciated. Thanks in advance. Martin

« previous php.general (#36961) next »