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: 052917

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

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 - 2017 psacake.com | My3C's

Version 7.2 | Advertise on this site