Format Date with No Separators

The FormatDateNoSep function returns mmddyyyy, or mmddyy.

Syntax:

noseparators = FormatDateNoSep(datevar,2 or 4)
Example Usage:
<% = FormatDateNoSep(date(),2) %>
Returns: 101124

and
<% = FormatDateNoSep(date(),4) %>
Returns: 10112024

ASP Source Code:
<%
Function FormatDateNoSep(DateValue, yrDig)
    Dim strYYYY
    Dim strMM
    Dim strDD

        strYYYY = CStr(DatePart("yyyy", DateValue))
        
        if yrDig = 2 then strYYYY = Right(strYYYY, 2)


        strMM = CStr(DatePart("m", DateValue))
        If Len(strMM) = 1 Then strMM = "0" & strMM

        strDD = CStr(DatePart("d", DateValue))
        If Len(strDD) = 1 Then strDD = "0" & strDD

        FormatDateNoSep = strMM & strDD & strYYYY

End Function 
%>


Jake asp vbscript date formatmediumdate formatdatelong iwnm


Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site