converting datetime to float in sql

converting datetime to float in sql

Hello, I have a question, how do I convert the difference of the following dates, for example: (2023-01-02 18:00:00)-(2023-01-01 17:00:00) into a decimal number?

I know how the conversion to an integer happens(cast(cast(test as date) – cast(testtwo as date) as int), but here I am confused.

>Solution :

You man look at DATEDIFF function. It allows you to:

returns the count (as a signed integer value) of the specified
datepart boundaries crossed between the specified startdate and

Then, convert the seconds to a day:

SELECT DATEDIFF(SECOND, '2023-01-01 17:00:00', '2023-01-02 18:00:00') * 1.0 / (60*60*24) -- 1.041666666666

Leave a Reply