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

SQL Server Round hours

I need to rounding time near 30 minutes.

This is an example:

1 minute -> 0,02 hours -> 0,5 hours

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

35 minutes -> 0.8 hours -> 1 hour

>Solution :

Use CEILING() (or CEIL(), for other DBMS) to round up:

SELECT CEILING(1  / 30.0)*30   --> 30 minutes
SELECT CEILING(25 / 30.0)*30  --> 30 minutes
SELECT CEILING(35 / 30.0)*30  --> 60 minutes

or if you prefer hours:

SELECT CEILING(1  / 30.0)*30 / 60 --> 0.5 hour
SELECT CEILING(25 / 30.0)*30 / 60 --> 0.5 hour
SELECT CEILING(35 / 30.0)*30 / 60 --> 1 hour
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