sql - how do I subtract date oracle with one record -
i have table 1 column in date format. want calculate time difference between 2 records, can me? need query in sql or pl/sql.
order_id;order_status_id;order_date 8296;16;22-2-2011 13:56:31 8295;22;22-2-2011 13:07:15
the query should result in 00:49:45 or close this.
can help? thx!
br
the question isn't how want calculate - how want shown. date arithmetic simple:
select date2 - date1 (select to_date('22-2-2011 13:07:15','dd-mm-yyyy hh24:mi:ss') date1, to_date('22-2-2011 13:56:31','dd-mm-yyyy hh24:mi:ss') date2 dual);
gives answer, decimal. how translate visual display?
select to_char(trunc(sysdate) + mod(date2 - date1,1),'hh24:mi:ss') (select to_date('22-2-2011 13:07:15','dd-mm-yyyy hh24:mi:ss') date1, to_date('22-2-2011 13:56:31','dd-mm-yyyy hh24:mi:ss') date2 dual);
ok, nicely formatted.
oh, except if want store interval? or if interval more 1 day need format differently.
so - need actual interval other purposes? or want display interval in given format? depending on need guide answer.
but interval easy. subtraction. in case
select yt2.order_date - yt1.order_date yourtable yt1, yourtable yt2 yt1.order_id = 8295 , yt2.order_id = 8296;
Comments
Post a Comment