Compare dates

Hello

     I have a field that stores date in this way

2011-05-07 12:35:47

, and I want to retrieve all the fields are stored today and
yesterday
i tried to test query like this But it did not retrieve any fields

select * from Staff_logs where  timestamp = CURRENT_DATE and timestamp = CURRENT_DATE - INTERVAL 1 DAY 

Instead of ‘TIMESTAMP’ use the name of the column containing the timestamp.
And the column can never be equal to today’s date AND yesterdays date. Use BETWEEN instead:


SELECT * 
FROM Staff_logs 
WHERE columnname BETWEEN CURRENT_DATE AND CURRENT_DATE - INTERVAL 1 DAY

column name is timestamp

i tried this query but still no results

I would change it. Timestamp is a reserved SQL word.
Unless you want to use them awfull back-ticks all the time.

i want to solve it without change column name, database for open source software

Put back-ticks around the column name.
`

SELECT * 
FROM Staff_logs 
WHERE `TIMESTAMP` BETWEEN CURRENT_DATE AND CURRENT_DATE - INTERVAL 1 DAY

Still the problem exists:(

your problem is the BETWEEN values

it’s the same as if i asked you which letters are between G and E

they’re in the wrong sequence

Oops, missed that :blush:

i tried this but still problem exists

SELECT *
FROM Staff_logs
WHERE `TIMESTAMP` BETWEEN CURRENT_DATE AND CURRENT_DATE - INTERVAL 3 DAY
SELECT * 
FROM Staff_logs 
WHERE `TIMESTAMP` BETWEEN CURRENT_DATE - INTERVAL 3 DAY AND CURRENT_DATE

Oooooooooh
that’s work good , thanks :slight_smile:

you’re welcome :smiley: :smiley: