1DECLARE
2 @start_dt DATETIME2= '2019-12-31 23:59:59.9999999',
3 @end_dt DATETIME2= '2020-01-01 00:00:00.0000000';
4
5SELECT
6 DATEDIFF(year, @start_dt, @end_dt) diff_in_year,
7 DATEDIFF(quarter, @start_dt, @end_dt) diff_in_quarter,
8 DATEDIFF(month, @start_dt, @end_dt) diff_in_month,
9 DATEDIFF(dayofyear, @start_dt, @end_dt) diff_in_dayofyear,
10 DATEDIFF(day, @start_dt, @end_dt) diff_in_day,
11 DATEDIFF(week, @start_dt, @end_dt) diff_in_week,
12 DATEDIFF(hour, @start_dt, @end_dt) diff_in_hour,
13 DATEDIFF(minute, @start_dt, @end_dt) diff_in_minute,
14 DATEDIFF(second, @start_dt, @end_dt) diff_in_second,
15 DATEDIFF(millisecond, @start_dt, @end_dt) diff_in_millisecond;
1SELECT t1.OrderNo,DATEDIFF(day,t1.LoadedStartDate,t2.LoadedStartDate)
2FROM UnnamedTableFromQuestion t1
3 INNER JOIN
4 UnnamedTableFromQuestion t2
5 on
6 t1.OrderNo = t2.OrderNo
7WHERE t1.OpNo = 1 and
8 t2.OpNo = 4
9
10////////////////////////////////////////////////////////////////
11
12select cur.unique_id_field, cur.seq_no, cur.date_created ,
13
14 datediff(second, prv.date_created, cur.date_created) as diff_in_seconds
15
16from yourtable as cur
17
18 join yourtable as prv
19
20 on cur.seq_no = prv.seq_no + 1;
1SELECT (END_DATE - START_DATE) Days-Total FROM MyTable
2/*this works for oracle sql*/