Jump to content


Photo

Query to select single date from datetime field


  • Please log in to reply
2 replies to this topic

#1 bryan11

bryan11
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 September 2006 - 10:16 PM

I've been searching records using ranges of dates with this kind of select statement:

select * from Orders where Orders.BillName="Village Pantry" and Orders.ShipDate >= '2006-07-25';

Orders.ShipDate is a datetime field. Now I need to select rows from an exact date, but this doesn't yield any results though many rows exist with this date:

select * from Orders where Orders.BillName="Fred's" and Orders.ShipDate = '2006-07-25';

I tried several variations on this and the results got weird. For example, using the following query I get dates from 7/24/06 to 7/25/06:

select * from Orders where Orders.BillName="Fred's" and Orders.ShipDate < '2006-07-26' and Orders.ShipDate > '2006-07-24' and Orders.QuickBooks != '' order by Orders.ShipDate;

How may I select records only for '2006-07-25' ?

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 12 September 2006 - 10:33 PM

Provided you have a recent version of MySQL, use DATE(Orders.ShipDate) = '2006-07-25'.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 bryan11

bryan11
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 September 2006 - 10:43 PM

Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users