I am doing some calculation but my calculation is off because my date field is showing the time-stamp and i only want to use as Date only when i am doing the calculation. How can i just ignore the minutes and just use the date when doing the calculation? Here is what i have:
SELECT EF.DSCH_TS,
CASE WHEN EXTRACT (DAY FROM EF.DSCH_TS - EF.ADMT_TS)>=0 THEN 'GroupA' END AS CAL
FROM MainTable EF;
You may want to consider rewriting your case statement to return an interval. This will allow for a little more flexibility.
Use
date_trunc()
with the first argument of'day'
. I think this is what you want:Netezza has built-in function for this by simply using:
This will return just the date portion of the timetamp and much more useful than casting it to a string with
TO_CHAR()
because it will work inGROUP BY
,HAVING
, and with other netezza date functions. (Where as theTO_CHAR
method will not)Also, the
DATE_TRUNC()
function will pull a specific value out of Timestamp ('Day', 'Month, 'Year', etc..) but not more than one of these without multiple functions and concatenate.DATE() is the perfect and simple answer to this and I am surprised to see so many misleading answers to this question on Stack. I see
TO_DATE
a lot, which is Oracle's function for this but will not work onNetezza
.With your query, assuming that you're interested in the days between midnight to midnight of the two timestamps, it would look something like this: