Formatting Hours and Minutes (Classic ASP)
And another old code segment, this time formatting "Hours" and "Minutes". The trick for the minutes is to return one of the quarter hours. If the minutes evaluate to "0", then "00" will return instead.
Function FormatMinutes(pIndex) Dim iMinutes, iIndex iIndex = cInt(pIndex) ' ---- Minutes = the remader of i/4 * 15 iMinutes = (iIndex mod 4) * 15 If iMinutes = 0 Then iMinutes = "00" FormatMinutes = iMinutes End Function Function FormatHours(pIndex,bFilterMilitary) Dim iHours, iIndex iIndex = cInt(pIndex) ' ---- Hours = the index divided by the number of quarter-hours: iHours = (iIndex/4) ' ---- Remove Remainders If inStr(1,iHours,".") Then iHours = left(iHours,instr(1,iHours,".")-1) ' ---- Remove military time? If bFilterMilitary = True Then _ If iHours > 12 Then iHours = iHours - 12 FormatHours = iHours End Function
Comments
1 comment posted<pre>
Function BuildDurationSelBox(pDurationSelectedIndex, bLocked)
Dim i, iDurationSelectedIndex, sSelected
iDurationSelectedIndex = cInt(pDurationSelectedIndex)
If bLocked = False Then
Response.Write "<select id='selDurationIndex' name='selDurationIndex'>"
For i = 1 to 20
If i = iDurationSelectedIndex Then sSelected = " SELECTED" Else sSelected = ""
Response.Write "<option value='" & i & "'" & sSelected & ">" & _
FormatHours(i,False) & " Hrs, " & FormatMinutes(i) & " Mins</option>"
Next
Response.Write "<option value='" & iThisProvidorCloseIndex - iThisProvidorStartIndex & "'" & sSelected & ">" & _
"All Day Event</option>"
Response.Write "</select>"
Else
Response.Write FormatHours(iDurationSelectedIndex,False) & _
" Hrs, " & FormatMinutes(iDurationSelectedIndex) & " Mins"
End If
End Function</pre>