Strip that hour, minute, second part out of my Date field in Oracle

I was trying to get a set of records in oracle with a certain date interval. I wanted to make sure that I only get the month, day and year part. Good  thing I had an oracle guru officatemate and told me that the TRUNC function strips out the hour, minute, second, etc. portion for me. Since I wasn't very comfortable using the BETWEEN clause in oracle, I went to a more conservative way of getting date intervals...

SELECT * FROM SOME_TBL WHERE TRUNC(date_field) >= TRUNC(ARG_START_DATE) AND TRUNC(date_field) <= TRUNC(ARG_END_DATE); 

I was doing it like TRUNC(date_field, 'MM/DD/YYYY')  but Iwas getting errors like, Too Many Precision Specifiers and sometimes Oracle Fetch out of Sequence.

Published Tuesday, May 13, 2008 3:28 AM by lamia
Filed under:

Comments

# re: Strip that hour, minute, second part out of my Date field in Oracle

Tuesday, May 13, 2008 11:00 AM by marl

How about the TO_DATE Function? Like:

TO_DATE(MyDate, 'DD/MM/YYYY')

But maybe this is too simplistic for you requirements.

# re: Strip that hour, minute, second part out of my Date field in Oracle

Tuesday, May 13, 2008 7:18 PM by lamia

I'm sure I tried it before. I forgot the reason why I didn't go for it. Thanks Marl.

Hmmm... Just this morning I was told that I should've used

TO_TIMESTAMP ('<start date>:00:00:00','MM.DD.YYYY:HH24:MI:SS')

and

TO_TIMESTAMP ('<end date>:23:59:59','MM.DD.YYYY:HH24:MI:SS')

instead. Lolz!

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: