How to convert the second to datetime format 108 hh: mm: ss in sql server without write function

    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 write 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 get it

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 be indicated as 00-00-000 00: 13: 00: 0000

+3
source share
2 answers

From what I understand, you need to take your estimated minutes (dated by you) and display this in a time format of 108.

This should convert the minutes to a date and time format of 108, i.e. hh: mm: ss

select convert(varchar
              ,dateadd(minute
                      , datediff(mi,v1.dateofchange,v2.dateofchange), '00:00:00')
              , 108
              )
+4
source

Short answer: you cannot.

Long answer:

First, the calculated value in minutes is interpreted as days in the CONVERT function. You need to divide by (24 * 60) to actually add minutes.

DATETIME 1753-9999 (MSDN).

Microsoft® SQL Server ™ , 1753 9999.

DATETIME2 ( SQL Server 2008?), 1. (MSDN)

Sql2008 , TIME, .

0

Source: https://habr.com/ru/post/1757787/


All Articles