Convert minutes to hours

# Thread: Convert minutes to hours

1. Senior Member
Join Date
Dec 1969
Posts
209

## Convert minutes to hours

Is there an easy way to convert minutes to hours...<BR> for example...<BR> tmeHours = formatminutes(93)<BR> tmeHours = 1:33

2. Senior Member
Join Date
Dec 1969
Posts
2,334

## RE: divide by 60

Dim min, hr<BR><BR>tmin = 245<BR>hr = split((tmin / 60),".")<BR>min = tmin mod 60<BR>Response.Write "hr = " & hr(0) & " Min =" & min

3. Senior Member
Join Date
Dec 1969
Posts
973

your base number will be minute_base = 60<BR><BR>1. hourStr=Divide the numbers to get your hour value:<BR>2. minuteStr= MOD the values to get the remainder, which will represent minutes<BR>3. put the values in a string (hourStr&":"&minuteStr)<BR>4. return that string

4. Senior Member
Join Date
Dec 1969
Posts
2,334

## RE: forgot to build up the string

FinalString = hr(0) & ":" & min

5. Senior Member
Join Date
Dec 1969
Posts
209

## RE: forgot to build up the string

Thanks.. I used it... but I thought there was already something out there.

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## A better way...

Actually, two better ways:<BR><BR>&#060;%<BR>tmin = 245 &#039; or whatever<BR>hr = Int( tmin / 60 )<BR>min = tmin MOD 60<BR>timeString = hr & ":" & Right( "0" & min, 2 )<BR>%&#062;<BR><BR>You need to make the minutes into a 2 digit string, else you get times that look ugly, like:<BR> 3:4<BR><BR>And the alternative is<BR>&#060;%<BR>tmin = 245 &#039; or whatever<BR>hr = tmin[hl="yellow"] [/hl]60 <BR>min = tmin MOD 60<BR>timeString = hr & ":" & Right( "0" & min, 2 )<BR>%&#062;<BR>Yes, *really* a backslash in there! That&#039;s the VBS operator for INTEGER DIVISION. Really, (a b) is the same as INT(a / b), but why not use it when it is there?<BR><BR>[Okay, technically, it is the same as FIX(a / b), but that&#039;s the same thing for positive numbers.]<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Paulee *also* forgot...

...to ensure that you get a 2-digit string for the minutes.<BR><BR>But other than that...<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
209

## RE: A better way...

The definitely works!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•