Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
enddate.

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading