0

I have a database with the time it takes to process an order and I need to convert it to the total number of minutes in SQL.

I get how to do this with the HH:MM:SS format using

LTRIM(DATEDIFF(MINUTE, 0, ProcessTime))

However whenever the time goes past a day the format becomes DD.HH:MM:SS

The "." after the D is what's throwing me off and it's returning an error when I try to run the code.

FutbolFan
  • 13,235
  • 3
  • 23
  • 35
amachin
  • 27
  • 3

1 Answers1

1

Assuming the values are stored as strings (as that is the only way it would be possible to store DD.HH:MM:SS)

WITH T(D) AS
(
SELECT '04.12:07:59' UNION ALL
SELECT '12:07:59'
)
SELECT D,
       CAST(LEFT(D,LEN(D)-8) AS float) * 24 * 60 + DATEDIFF(MINUTE, 0, RIGHT(D,8)) AS Mins
FROM T

Returns

+-------------+------+
|      D      | Mins |
+-------------+------+
| 04.12:07:59 | 6487 |
| 12:07:59    |  727 |
+-------------+------+
Martin Smith
  • 438,706
  • 87
  • 741
  • 845