tags:

views:

35

answers:

3

I have a timestamp and I want to search for a single date but I can't figure out how to do this.

SELECT something from mytable WHERE timestamp = 'desiredDate'

If I include the hours mins and seconds in a range I can get it but there has to be a way to tell mysql that you want everything for a single day. Can someone please help? Thanks.

A: 

How about

SELECT something from mytable WHERE timestamp > 'desiredDate+00:00:00' and timestamp < 'desiredDate+23:59:59'

Or similar...

ppuschmann
Can I specify the hours,etc in the query without the user having to do so?
+1  A: 

You could use TO_DAYS to turn the timestamp into a day number, then compare that with the desired day number:

SELECT foo FROM mytable WHERE TO_DAYS(timestamp) = TO_DAYS('2009-09-07');
Paul Dixon
Bingo! Thanks a bunch Paul! Worked like a sharm.
A: 

You could

SELECT myField FROM myTable WHERE timestamp LIKE '2009-08-07%'

to get all entries of a certain day.

IkoTikashi