Answer the question
In order to leave comments, you need to log in
How to make the date displayed by the number of hours in the database?
I have a field that displays a time difference and it splits the time into hours, minutes, seconds. I want to display this field so that it only shows the difference in hours with a single float value. How to do it?
Answer the question
In order to leave comments, you need to log in
-- Let @t_start be a start date in the past, for example 1111 minutes ago
DECLARE @t_start AS DATETIME = DATEADD(minute, -1111, GETDATE())
-- Find out how many hours have passed since that time as a FLOAT using
SELECT DATEDIFF(second , @t_start, getdate()) / 3600.0
assuming that the variable is of type DATETIME, then something like this:
-- дата начала
DECLARE @t_start AS DATETIME = DATEADD(minute, -7410, GETDATE());
-- дата конца
DECLARE @t_finish AS DATETIME = GETDATE();
-- разница между датами начала и конца в переменной типа DATETIME
DECLARE @t_diff AS DATETIME = @t_finish - @t_start;
-- разница между датами начала и конца
SELECT @t_diff;
SELECT DATEDIFF(second, DATEFROMPARTS(1900,1,1), @t_diff) / 3600.0 AS diff_h
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question