VB6Format

Trying to create VB6 "Format" function in Classic ASP, works now for date only, will add more as time permits.

CodeFunctionName
What is this?

Public

Tested

Original Work
Function VB6Format(DateTime, Format)
Rett = ""
For J = 1 To Len(Format)
If UCase(Mid(Format, J, 4)) = "YYYY" Then
Rett = Rett & Year(DateTime)
J = J + 3
ElseIf UCase(Mid(Format, J, 3)) = "YYY" Then
Rett = Rett & Right(Year(DateTime), 3)
J = J + 2
ElseIf UCase(Mid(Format, J, 2)) = "YY" Then
Rett = Rett & Right(Year(DateTime), 2)
J = J + 1
ElseIf UCase(Mid(Format, J, 1)) = "Y" Then
Rett = Rett & Right(Year(DateTime), 1)
ElseIf UCase(Mid(Format, J, 4)) = "MMMM" Then
Rett = Rett & MonthName(DateTime, 1)
J = J + 3
ElseIf UCase(Mid(Format, J, 3)) = "MMM" Then
Rett = Rett & MonthName(DateTime, 2)
J = J + 2
ElseIf UCase(Mid(Format, J, 2)) = "MM" Then
Rett = Rett & Right("00" & Month(DateTime), 2)
J = J + 1
ElseIf UCase(Mid(Format, J, 1)) = "M" Then
Rett = Rett & Month(DateTime)
ElseIf UCase(Mid(Format, J, 4)) = "DDDD" Then
Rett = Rett & DayName(DateTime, 1)
J = J + 3
ElseIf UCase(Mid(Format, J, 3)) = "DDD" Then
Rett = Rett & DayName(DateTime, 2)
J = J + 2
ElseIf UCase(Mid(Format, J, 2)) = "DD" Then
Rett = Rett & Right("00" & Day(DateTime), 2)
J = J + 1
ElseIf UCase(Mid(Format, J, 1)) = "D" Then
Rett = Rett & Day(DateTime)
Else
Rett = Rett & Mid(Format, J, 1)
End If
Next
VB6Format = Rett
End Function

DateTime, Format

VB6Format(Date, "ddd dd mmm 'yy)
Tue 24 Jul '18
VB6Format(Date, "yyyy-mmm-d")
2018-Mar-4

Views 5,691

Downloads 1,466

CodeID
DB ID