sql - Subtracting two dates using PostgreSQL -
i trying subtract 2 dates each other seems not subtracting , not sure doing wrong here. using case statement flag 1 if difference between dates less 90 days else flag 0. flagging 1 if difference between dates greater 90 days. postgresql here , here case statement:
case when extract(day cast(svs_dt date) - cast(dsch_ts date)) <90 1 else 0 end fu90
example of dates here:
svs_dt dsch_ts 2013-03-22 00:00:00 2010-05-06 00:00:00
it suppose flag 0 in case flagging 1 because difference between these 2 dates greater 90 days.
extract
of day returns day element of date. since days between 1 , 31, maximum difference 30, , cannot larger 90.
subtracting date
s returns difference in days, integer. need drop extract
calls:
case when (cast(svs_dt date) - cast(dsch_ts date)) < 90 1 else 0 end fu90
sql postgresql date netezza
No comments:
Post a Comment