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
guido2004:
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
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:(
r937
January 2, 2012, 10:39am
9
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
altarek
January 2, 2012, 10:48am
11
i tried this but still problem exists
SELECT *
FROM Staff_logs
WHERE `TIMESTAMP` BETWEEN CURRENT_DATE AND CURRENT_DATE - INTERVAL 3 DAY
r937:
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
SELECT *
FROM Staff_logs
WHERE `TIMESTAMP` BETWEEN CURRENT_DATE - INTERVAL 3 DAY AND CURRENT_DATE
altarek
January 2, 2012, 10:58am
13
Oooooooooh
that’s work good , thanks