forked from jkstill/oracle-script-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
date_math.sql
34 lines (22 loc) · 881 Bytes
/
date_math.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- date_math.sql
-- date math examples
-- how to get the minutes between to dates of the same day
drop table date_math;
create table date_math ( start_date date, end_date date );
insert into date_math values( to_date('06/15/1999 06:00:00', 'mm/dd/yyyy hh24:mi:ss'), to_date('06/15/1999 06:45:32', 'mm/dd/yyyy hh24:mi:ss'));
commit;
select
to_char( ( end_date - start_date ) +trunc(sysdate) , 'hh24:mi:ss')
from date_math
/
delete from date_math;
insert into date_math values( to_date('06/12/1999 06:00:00', 'mm/dd/yyyy hh24:mi:ss'), to_date('06/15/1999 09:33:16', 'mm/dd/yyyy hh24:mi:ss'));
insert into date_math values( to_date('04/01/1957 06:00:00', 'mm/dd/yyyy hh24:mi:ss'), sysdate );
-- days and minutes
select
--days
floor( end_date - start_date ) || ':' ||
-- minutes
to_char( ( end_date - start_date ) +trunc(sysdate) , 'hh24:mi:ss')
from date_math
/