In SQL 2008 why do I get an error when I do this:
select datediff (minute, '23:30','24:00')
The error is :
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
Even if I were to change 24:00 to 00:00 why does the result say -1410?
What are the alternatives that I could use for this please?
If you are looking for the difference between ’23:30′ and ’24:00′ – which technically is the next day, then you will use
When you use:
the ’00:00′ is being interpreted as the same day that is why you are getting
-1410. There are a total of 1440 minutes in the day minus 30 minutes as the difference. TheDATEDIFFfunction is:If your end date ’00:00′ is before your start date then you will get a negative number.
Edit:
Based on your comment you will use the following for your table, then use a
CASEstatement around theendtimeto add a day to it:See SQL Fiddle with Demo