Hello,
How can I convert time HH:MM format to decimal format ?
for ex
3:00 to 3
3:15 to 3.25
3:30 to 3.5
3:45 to 3.75
Can any one help?
Hello,
How can I convert time HH:MM format to decimal format ?
for ex
3:00 to 3
3:15 to 3.25
3:30 to 3.5
3:45 to 3.75
Can any one help?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pasang TamangRank #449 · 5.6K reputationPosted Dec 30, 2022, 2:08 AM EST
Hi Deepak,
You can use DATEPART function to extract hour and minute separately and make the calculation. Check below SQL code for your reference.
Declare @dateTimeValue VARCHAR(10) = '03:15' SELECT CAST(DATEPART(hour, @dateTimeValue)+DATEPART(minute, @dateTimeValue) / 60.00 AS DECIMAL(7,4))Regards,
Pasang
Amit MohantyRank #112 · 20K reputationPosted Dec 30, 2022, 1:48 AM EST
Check this
Declare @yourValue VARCHAR(50) = '08:30' (SELECT CAST(LEFT(@yourValue, PATINDEX('%[:.]%', @yourValue) - 1) AS INT) + CAST(RIGHT(@yourValue, PATINDEX('%[:.]%', REVERSE(@yourValue)) -1 ) AS INT) / 60.0)