Wednesday, August 7, 2013

SQL to retrieve the difference between DATES

Method 1: SELECT t1_id, EXTRACT(Day FROM(mod_date_time – create_date_time) DAY TO SECOND) as Day, EXTRACT(HOUR FROM(mod_date_time – create_date_time) DAY TO SECOND) as Hour, EXTRACT(Minute FROM(mod_date_time – create_date_time) DAY TO SECOND) as Minute, EXTRACT(SECOND FROM(mod_date_time – create_date_time) DAY TO SECOND) as second FROM t1; Method 2: SELECT floor((date1-date2)*24) || ' HOURS ' || mod(floor((date1-date2)*24*60),60) || ' MINUTES ' || mod(floor((date1-date2)*24*60*60),60) || ' SECS ' time_difference FROM dates;

No comments: