VB6Format

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

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

Parameters

DateTime, Format

Examples

VB6Format(Date, &#34;ddd dd mmm &#39;yy)<br/>Tue 24 Jul &#39;18<br/>VB6Format(Date, &#34;yyyy-mmm-d&#34;)<br/>2018-Mar-4

Views 147 Downloads 58

Perm link