Recommended ASP Format the DATE function (output 13 styles)

Source: Internet
Author: User
Tags date format exit end
function | date

'================================================
' Function name: formatdate
' Function: Format date
' Parameters: DateAndTime----Original date and time
' Para----date format
' Return value: the date formatted
'================================================
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



Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.