<%
'==============================================
' cvDateFormat
' Author : John Lovell
' Company : CodeValve.com
' Date : NOV 2002
' NOTES:
' This class was created to have a more controlled date format
'
' You are free to use this code anywhere as long as it stays
' unchanged and this comment block remains.
' This class is posted as is.
' Use it at your own risk.
' There are NO warrantees or guarantees
' associated with it's use.
'
'==============================================
'
' Format strings : Date = 11/01/2003 (November 1st 2003)
'
' "yyyy/mm/dd" = 2003/11/01
' "dd/mm/yy" = 01/11/03
' "dd/mm/yyyy" = 01/11/2003
' "yyyy-mm-dd" = 2003-11-03
' "yy-mm-dd" = 03-11-01
' "dd-mm-yy" = 01-11-03
' "dd-mm-yyyy" = 01-11-2003
' "ddmmyyyy" = 01112003
' "ddmmyy" = 011103
' "mmddyy" = 110103
' "mmddyyyy" = 11012003
' "yyyymmdd" = 20031101
' "yymmdd" = 031101
' "yyyy" = 2003
' "Short" = 1/11/2003
' "Long" = Saturday, November 01, 2003
' "SiteDate" = Saturday, 1st of November, 2003
' "dd-Month-yyyy" = 01-Nov-2003
' "dd-Month-yy" = 01-Nov-03
' "DayName" = Saturday
' "DayNameAbbr" = Sat
'
'
'===============EXAMPLE====================================
'Set cvDate = new cvDateFormat
'Response.Write(cvDate.fixDate("11/01/2003","SiteDate"))
'Set cvDate = Nothing
'==========================================================
Class cvDateFormat
' Use: fixDate(valid date string, format string)
Public Function fixDate(strDate,format)
d = DatePart("D",strDate)
m = DatePart("M",strDate)
y = DatePart("YYYY",strDate)
if len(d) < 2 then
d = "0" & d
end if
if len(m) < 2 then
m = "0" & m
end if
Select Case Format
Case "yyyy/mm/dd"
fixDate = y & "/" & m & "/" & d
Case "yy/mm/dd"
fixDate = right(y,2) & "/" & m & "/" & d
Case "dd/mm/yy"
fixDate = d & "/" & m & "/" & right(y,2)
Case "dd/mm/yyyy"
fixDate = d & "/" & m & "/" & y
Case "yyyy-mm-dd"
fixDate = y & "-" & m & "-" & d
Case "yy-mm-dd"
fixDate = right(y,2) & "-" & m & "-" & d
Case "dd-mm-yy"
fixDate = d & "-" & m & "-" & right(y,2)
Case "dd-mm-yyyy"
fixDate = d & "-" & m & "-" & y
Case "ddmmyyyy"
fixDate = d & m & y
Case "ddmmyy"
fixDate = d & m & right(y,2)
Case "mmddyy"
fixDate = m & d & right(y,2)
Case "mmddyyyy"
fixDate = m & d & y
Case "yyyymmdd"
fixDate = y & m & d
Case "yymmdd"
fixDate = right(y,2) & m & d
Case "yyyy"
fixDate = y
Case "Short"
fixDate = formatdatetime(strDate,vbShortDate)
Case "Long"
fixDate = formatdatetime(strDate,vbLongDate)
Case "dd-Month-yyyy"
m = MonthName (m,True)
fixDate = d & "-" & m & "-" & y
Case "dd-Month-yy"
m = MonthName (m,True)
fixDate = d & "-" & m & "-" & right(y,2)
Case "DayName"
fixDate = WeekDayName(Weekday(strDate),False)
Case "DayNameAbbr"
fixDate = WeekDayName(Weekday(strDate),True)
Case "SiteDate"
fixDate = WeekDayName(Weekday(strDate),False) & ", " & DateSuffix(DatePart("D",strDate)) & " of " & MonthName(m,false) & ", " & fixDate(strDate,"yyyy")
Case "Stamp"
fixDate = fixdate(Now(),"yyyymmdd") & fixTime(Now(),"Stamp")
Case Else
fixDate = d & "/" & m & "/" & y
End Select
End Function
Private Function DateSuffix(num)
Dim x
if num < 13 or num > 20 then
Select Case right(num,1)
Case "0"
x = "th"
Case "1"
x = "st"
Case "2"
x = "nd"
Case "3"
x = "rd"
Case else
x = "th"
End Select
End if
If num > 12 and num < 21 then
x = "th"
End If
DateSuffix = num & x
End Function
Public Function fixTime(strTime,format)
h = Hour(strTime)
m = Minute(strTime)
s = Second(strTime)
if s < 10 then
s = "0" & s
end if
if m < 10 then
m = "0" & m
end if
if h < 10 then
h = "0" & h
end if
Select Case format
Case "hh:mm:ss"
fixTime = h & ":" & m & ":" & s
Case "hhmmss"
fixTime = h & m & s
Case "Stamp"
fixTime = h & m & s
Case Else
fixTime = formatdatetime(strTime,vbShortTime)
End Select
End Function
End Class
'Another Example
'Set cvDate = new cvDateFormat
'Response.Write(cvDate.fixDate(Now(),"Stamp"))
'Set cvDate = Nothing
%>