Computing time with Oracle sysdate

If you ever need to work with something other than a day when using sysdate you are in luck. As it turns out you can work on sysdate with fractional days. This is just what a person needs when they want to do something like:

SELECT mycol FROM sometable WHERE sometimestamp < "30 seconds ago"

The main trick here is to know that sysdate math is based in days and fractional days work. Here are a few examples:

Remove hours from a date:

sysdate - hours/hours in a day

Remove minutes from a date:

sysdate - minutes/(hours in a day * minutes in an hour)
or
sysdate - minutes/minutes in a day

Remove seconds from a date:

sysdate - seconds/(hours in a day * minutes in an hour * seconds in a minute)
or
sysdate - seconds/seconds in a day

The example above would be:

SELECT mycol FROM sometable WHERE sometimestamp < sysdate - 30/(24*60*60)
del.icio.us:Computing time with Oracle sysdate digg:Computing time with Oracle sysdate spurl:Computing time with Oracle sysdate wists:Computing time with Oracle sysdate simpy:Computing time with Oracle sysdate newsvine:Computing time with Oracle sysdate blinklist:Computing time with Oracle sysdate furl:Computing time with Oracle sysdate reddit:Computing time with Oracle sysdate fark:Computing time with Oracle sysdate blogmarks:Computing time with Oracle sysdate Y!:Computing time with Oracle sysdate smarking:Computing time with Oracle sysdate magnolia:Computing time with Oracle sysdate segnalo:Computing time with Oracle sysdate gifttagging:Computing time with Oracle sysdate

Leave a Reply