ASP format date into required format _ application Tips
Source: Internet
Author: User
<%
'******************************
' Function: FormatDate (DATEANDTIME, para)
' Parameters: DateAndTime, date time to format; para, style.
' Author: Arisisi
' Date: 2007/7/12
' Description: Format the date as needed
' Example: <%=formatdate (Now (), 3)%>
'******************************
Public Function formatdate (DateAndTime, para)
On Error Resume Next
Dim y, M, D, H, MI, S, strdatetime
FormatDate = DateAndTime
If not IsNumeric (para) Then Exit Function
If not IsDate (dateandtime) Then Exit Function
y = CStr (year (dateandtime))
m = CStr (Month (DateAndTime))
If Len (m) = 1 Then m = "0" & M
D = CStr (Day (DateAndTime))
If Len (d) = 1 Then D = "0" & D
h = CStr (Hour (DateAndTime))
If Len (h) = 1 Then h = "0" & H
Mi = CStr (Minute (DateAndTime))
If Len (mi) = 1 Then mi = "0" & mi
s = CStr (Second (DateAndTime))
If Len (s) = 1 Then s = "0" & S
Select Case Para
Case "1"
Strdatetime = y & "-" & M & "-" & D & "" & H & ":" & Mi & ":" & S
Case "2"
Strdatetime = y & "-" & M & "-" & D
Case "3"
Strdatetime = y & "/" & M & "/" & D
Case "4"
Strdatetime = y & "Year" & M & "Month" & D & "Day"
Case "5"
Strdatetime = M & "-" & D & "" & H & ":" & mi
Case "6"
Strdatetime = M & "/" & D
Case "7"
Strdatetime = M & "Month" & D & "Day"
Case "8"
Strdatetime = y & "Year" & M & "Month"
Case "9"
Strdatetime = y & "-" & M
Case "10"
Strdatetime = y & "/" & M
Case "11"
Strdatetime = Right (y,2) & "-" &m & "-" & D & "" & H & ":" & mi
Case "12"
Strdatetime = Right (y,2) & "-" &m & "-" & D
Case "13"
Strdatetime = M & "-" & D
Case Else
Strdatetime = DateAndTime
End Select
FormatDate = Strdatetime
End Function
%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.