views:

251

answers:

2

Ok I think I'm getting the previous year instead of the previous day, but I need to previous day.

SELECT TO_DATE(TO_CHAR(CURRENT_DATE, 'YYYY-MM-DD'),'YYYY-MM-DD') - 1 FROM Dual

I'm comparing it to a datetime stamp in this format and wish to get all the rows from the previous day.

YYYY-MM-DD HH:MM:SS

So I'm trying something like this

SELECT field,datetime_field 
FROM database
WHERE datetime_field > TO_DATE(TO_CHAR(CURRENT_DATE, 'YYYY-MM-DD'),'YYYY-MM-DD') - 1
+2  A: 
SELECT field,datetime_field 
FROM database
WHERE datetime_field > (CURRENT_DATE - 1)

Its been some time that I worked on Oracle. But, I think this should work.

shahkalpesh
CURRENT_DATE adds the time, I just want the date
Phill Pafford
+4  A: 

how about sysdate?

SELECT field,datetime_field 
FROM database
WHERE datetime_field > (sysdate-1)
eschneider
SYSDATE adds the time, I just want the date
Phill Pafford
trunc(sysdate-1)
eschneider
TRUNC() nice! Didn't think to use this
Phill Pafford
trunc(current_date) works also. current_date = Oracle session time zone; sysdate = Oracle Server date and time.
eschneider