Re: Selecting date range from database

From: Date: Wed, 26 Mar 2003 18:40:19 +0000
Subject: Re: Selecting date range from database
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-141106@lists.php.net to get a copy of this message
> I am trying to select a date range in this format from a database 1-Mar-03 > to 26-Mar-03. The date is stored in a mySQL database in that format and when > doing a normal select it just selects the dates as if they are numbers. > > How can I make this select work the way I want it to work? I am using the > following query: > > "SELECT * FROM members WHERE member_date >= '01-Mar-03' AND member_date <= > '26-Mar-03' ORDER BY member_date"; Your dates are just strings. You can't say whether one string is greater or less than another. How do you expect MySQL to know they are dates. Use a DATE column like you're supposed to, and you can do the query just like you have it above. The MySQL format for dates is YYYY-MM-DD. You can use the DATE_FORMAT() function to re-format it back into DD-MMM-YY if that's what you really need to show. Or, you could do the whole thing with Unix timestamps and and INT column. The way you have it now, you're kind of screwed. ---John Holmes...

« previous php.general (#141106) next »