A function that handles various date formats

Source: Internet
Author: User
function <%
'----Date conversion function-----
function Wf_datetochar (datetime,l)
'---------explain------------
' DateTime is the date value you want to convert
' L is the level you want to convert to, and can be set to ' d ', ' n ' and ' s '
' d ' refers to the conversion of the Yyyy-mm-dd form
"N" refers to the conversion of YYYY-MM-DD hh:mm form
' "s" refers to the conversion of YYYY-MM-DD hh:mm:ss form
' Long ' is the form that translates into the yyyy year mm month DD Day
' No ' refers to the form of conversion to YYYYMMDD
' Short ' refers to the form of conversion to YYMMDD
' t ' refers to the form of conversion to YYMMDD hh:mm
'-------------------------
Dim ls_date,ls_getstr
If IsNull (l) or trim (l) = "" Then l= "s"
If IsDate (datetime) Then
LS_DATE=CSTR (DateTime)
' Writeln ls_date
Ls_getstr=datepart ("yyyy", CDate (ls_date))
Ls_getstr=ls_getstr & "-" & Wf_ctonstr (DatePart ("M", CDate (Ls_date)), 2)
Ls_getstr=ls_getstr & "-" & Wf_ctonstr (DatePart ("D", CDate (Ls_date)), 2)
If l= "D" then wf_datetochar=ls_getstr
Ls_getstr=ls_getstr & "" & Wf_ctonstr (DatePart ("H", CDate (Ls_date)), 2
Ls_getstr=ls_getstr & ":" & Wf_ctonstr (DatePart ("N", CDate (Ls_date)), 2)
If l= "n" then Wf_datetochar=ls_getstr
Ls_getstr=ls_getstr & ":" & Wf_ctonstr (DatePart ("s", CDate (Ls_date)), 2)
If l= "s" then wf_datetochar=ls_getstr
If l= "Long" then Wf_datetochar=datepart ("yyyy", CDate (ls_date)) & "Year" &wf_ctonstr (DatePart ("M", CDate (Ls_date) ), 2 & "Month" &wf_ctonstr (DatePart ("D", CDate (Ls_date)), 2) & "Day"
If l= "No" then Wf_datetochar=datepart ("yyyy", CDate (ls_date)) &wf_ctonstr (DatePart ("M", CDate (Ls_date)), 2 & Wf_ctonstr (DatePart ("D", CDate (Ls_date)), 2)
If l= "short" then Wf_datetochar=right (DatePart ("yyyy", CDate (Ls_date)), 2) &wf_ctonstr (DatePart ("M", CDate (Ls_ Date)), 2) &wf_ctonstr (DatePart ("D", CDate (Ls_date)), 2)
If l= "T" then Wf_datetochar=wf_ctonstr (DatePart ("M", CDate (Ls_date)), 2 &wf_ctonstr (DatePart ("D", CDate (Ls_date) ), 2 & "" & Wf_ctonstr (DatePart ("H", CDate (Ls_date)), 2) & ":" & Wf_ctonstr (DatePart ("N", CDate (ls_date)) , 2)

Else
Wf_datetochar=null
End If

End Function
'----Converts an integer to a two-bit integer----"1" to "01"
function Wf_ctonstr (num,n)
If not isnumeric (num) Then
Wf_ctonstr=num
Else
If Len (CInt (num)) >=n Then
WF_CTONSTR=CSTR (CInt (num))
Else
Wf_ctonstr= "0" &cstr (CInt (num))
While Len (WF_CTONSTR) <n
Wf_ctonstr= "0" &cstr (WF_CTONSTR)
Wend
End If
End If
End Function
'-----------------------------------

%>



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.