sql - difference between two timestamps (in days) in oracle -


select min (snap_id) first_snap,      max (snap_id) last_snap,      min (begin_interval_time) first_query,      max (end_interval_time) last_query,      max(end_interval_time) - min(begin_interval_time) "time_elapsed" dba_hist_snapshot order snap_id;  2931    3103    5/28/2012 6:00:11.065    6/4/2012 11:00:40.967    +07 05:00:29.902000 

i last columns output 7 (for days). have tried trunc , extract other posts mentioned can't seem syntax right. ideas?

judging comment, you're using timestamp columns, not datetime. use extract retrieve hour difference, , trunc(.../24) whole number of days:

trunc(extract(hour max(end_interval_time) - min(begin_interval_time))/24) 

or cast timestamp date:

trunc(cast(max(end_interval_time) date) -     cast(min(begin_interval_time) date)) 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -