Access SQL Function to Convert Seconds to HH:MM

K

Kayda

Hi:

I have a number in seconds that I need to convert to an HH:MM string
in Access SQL code. How to do?

Thanks,
Kayda
 
K

Kayda

I found this on an older forum:

Format(Int([Field1]/3600),"00") & ":" & Format(Int(([Field1]-
(Int([Field1]/3600)*3600))/60),"00") & ":" & Format((([Field1] Mod
60)),"00")

and, that works, but I can't just remove the end bit (the "seconds"
bit) as that won't round my minutes(and hours where applicable) i.e.

170 seconds
=00:02:50
=00:02 using this formula
=00:03 using proper rounding

3599 seconds
= 00:59:59
= 00:59 using this formula
= 01:00 using proper rounding

How to do?

Thanks,
Kayda
 
J

John W. Vinson

Hi:

I have a number in seconds that I need to convert to an HH:MM string
in Access SQL code. How to do?

[seconds] \ 3600 & Format([seconds] \ 60 MOD 60, "\:00")

This will discard the seconds. The backslash is an integer divide operator (or
a take-the-next-format-character-literally command).

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top