I have the following TSQL query to get a different date time value:
SELECT CONVERT(DATETIME, EndDtField - StartDtField, 120) AS Duration FROM myTable;
The result will be:
Duration 1900-01-01 23:02:04.000 ....
I tried to get a partial row from a result similar to this 01 23:02:04.000 using the RIGHT() function (actually it is preferable in the format 01 23:02:04 without 000 ):
SELECT RIGHT(CONVERT(DATETIME, EndDtField - StartDtField, 120), 15) AS Duration FROM myTable;
Result:
Duration 1 1900 11:02PM ...
It appears that the value of RIGHT(..) is a datetime value. Even I specify the datetime value in the format yyyy-mm-dd hh:mi:ss , but still I can not get the expected result. How can I get a partial day and time string ( dd hh:mi:ss ) from Duration? I really don't like parsing the values ββof day , hour , minute and second , and then building the string.
Any other alternatives?
source share