If you want an ASP solution for the missing Format function that you might have liked in Visual Basic,
here’s a version in VBScript:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Function LeftPad
'
' This code adds leading zeroes to a number. This function is used
' by FormatDT to properly format dates and times.
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function LeftPad(intNumber, intDigits)
Dim strResult
Dim strTemp
Dim i
strTemp = CStr(intNumber)
strResult = String(intDigits - Len(strTemp), "0")
strResult = strResult & strTemp
LeftPad = strResult
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Function FormatDT
'
' This function allows date/time values to be formatted more flexibly
' than is allowed by the built-in FormatDateTime function.
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function FormatDT(datInput, strFormat)
Dim strResult ' As String
Dim intTemp ' As Integer
Dim strTemp ' As String
strResult = strFormat
strResult = Replace(strResult, "#YEAR_LONG#", Year(datInput), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#YEAR_SHORT#", Right(Year(datInput), 2), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#MONTH_NAME#", MonthName(Month(datInput)), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#MONTH_NAME_SHORT#", Left(MonthName(Month(datInput)), 3), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#MONTH_2DIGIT#", LeftPad(Month(datInput), 2), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#MONTH_1DIGIT#", Month(datInput), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#DAY_2DIGIT#", LeftPad(Day(datInput), 2), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#DAY_1DIGIT#", Day(datInput), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#HOUR_2DIGIT#", LeftPad(Hour(datInput), 2), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#HOUR_1DIGIT#", Hour(datInput), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#MINUTE_2DIGIT#", LeftPad(Minute(datInput), 2), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#MINUTE_1DIGIT#", Minute(datInput), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#SECOND_2DIGIT#", LeftPad(Second(datInput), 2), 1, -1, vbTextCompare)
strResult = Replace(strResult, "#SECOND_1DIGIT#", Second(datInput), 1, -1, vbTextCompare)
FormatDT = strResult
End Function
You can additional formatting options as long as the name is unique. The LeftPad function allows you to create times like 05:04:02 using the _2DIGIT tags.