Re: Selecting Dates

From: Date: Sun, 08 Apr 2001 18:53:54 +0000
Subject: Re: Selecting Dates
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47654@lists.php.net to get a copy of this message
Hello Jordan, On 08-Apr-01 06:58:16, you wrote: >I'm trying to select records based on dates. >I have a table with dates in the format 2001-04-08 and I'm using the query: >SELECT name, description, date_time FROM events WHERE YEAR(date_time) = 2001 >AND MONTH(date_time) = 04 AND DAYOFMONTH(date_time) = 08 >But it doesn't yield any records? I don't really understand why? It seems to >be the last bit 'DAYOFMONTH(date_time) = 08' which cause a problem because if > I leave it out of the query, it selects all records for a particular month >in a particular year as expected. If you just want to retrict queries by specific dates, it's a database design mistake to keep date and time in the same field. Another mistake is to use functions like those that apply to the date fields you have selected. That prevents the database server to use any indexes on that field. To solve your problems you may have a query conditioon like: WHERE date_time>='2001-04-08 00:00:00' AND date_time<='2001-04-08 23:59:59' Regards, Manuel Lemos Web Programming Components using PHP Classes. Look at: http://phpclasses.UpperDesign.com/?user=mlemos@acm.org -- E-mail: mlemos@acm.org URL: http://www.mlemos.e-na.net/ PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp --

« previous php.general (#47654) next »