Military2TwelveHour Function:
Convert military time to twelve hour format.
Description:
Military2TwelveHour Function converts military time to twelve hour format.
Syntax:
time = Military2TwelveHour(timeinput)
Example:
<%
response.write Military2TwelveHour("1:15") '--- returns 1:15 AM
response.write Military2TwelveHour("22:45") '--- returns 10:45 PM
response.write Military2TwelveHour("18:32") '--- returns 6:32 PM
response.write Military2TwelveHour("10:01") '--- returns 10:01 AM
%>
ASP Source Code:
<%
Function Military2TwelveHour(inString) Dim sTmpString Dim sMinutes Dim sHours Dim sAMPM Dim i sTmpString = "" '--- first strip out all non-numeric characters For i = 1 To Len(inString) If IsNumeric(Mid(inString, i, 1)) Then sTmpString = sTmpString & Mid(inString, i, 1) End If Next '--- make sure we have enough numbers to create a time If Len(sTmpString) >= 2 Then '--- get hours and minutes sHours = Left(sTmpString, Len(sTmpString) - 2) If sHours = "" Then sHours = "00" sMinutes = Right(sTmpString, 2) '--- determine am/pm If sHours < 12 Then sAMPM = "AM" If sHours = 0 Then sHours = 12 Else sAMPM = "PM" If sHours > 12 Then sHours = sHours - 12 End If '--- return string sTmpString = sHours & ":" & sMinutes & " " & sAMPM Else '--- return empty string sTmpString = "" End If Military2TwelveHour = sTmpString End Function
%>
|