select v1.*, datediff(ss,v1.dateofchange,v2.dateofchange) as acutaltime
from vActualTime v1 left join vActualTime v2
on v1.rowno=v2.rowno-1
FK_PatientId FK_Status_PatientId DateofChange rowno acutaltime
------------ ------------------- ----------------------- -------------------- -----------
3 16 2010-08-02 15:43:46.000 1 757
3 24 2010-08-02 15:56:23.000 2 96
3 26 2010-08-02 15:57:59.000 3 NULL
I am using Sql server 2005
When I writes this
select v1.*, datediff(mi,v1.dateofchange,v2.dateofchange) as acutaltime,
convert(datetime,datediff(mi,v1.dateofchange,v2.dateofchange),108) as [date]
from vActualTime v1 left join vActualTime v2
on v1.rowno=v2.rowno-1
I gets this
FK_PatientId FK_Status_PatientId DateofChange rowno acutaltime date
------------ ------------------- ----------------------- -------------------- ----------- -----------------------
3 16 2010-08-02 15:43:46.000 1 13 1900-01-14 00:00:00.000
3 24 2010-08-02 15:56:23.000 2 1 1900-01-02 00:00:00.000
3 26 2010-08-02 15:57:59.000 3 NULL NULL
This should have been given as 00-00-000 00:13:00:0000
From what I understand you need to take your calculated minutes (the datediff you're doing) and display that in a time format 108.
This should convert the minutes to a datetime format of 108, i.e. hh:mm:ss
select convert(varchar
,dateadd(minute
, datediff(mi,v1.dateofchange,v2.dateofchange), '00:00:00')
, 108
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With