Formatting Date (DTS ActiveX script)

  • I am attempting to format the date to later include in the filename that the script creates. However, this line doesn't seem to work. Format shoudl be as YYYYMMDD. Can anyone tell me what I am doing wrong here?

    strDate = format(year(date), "yyyy") & format(month(date), "MM") & format(day(date), "dd")

    Thanks

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • Here's a couple of things you can try.

    http://learningpcs.blogspot.com/2011/03/vbscript-format-date-as-yyyy-mm-dd.html



    Everything is awesome!

  • I happened alone the below function that gets the job done. Your article referral looks to be a great resource too. Thanks!

    Function fnFormatDate(dtDate, strFormat)

    Dim yyyy, mm, dd

    mm = Month(dtDate)

    yyyy=Year(dtDate)

    dd=Day(dtDate)

    If (Len(dd)<2) then

    dd="0"&dd

    End If

    If (Len(mm)<2) then

    mm="0"&mm

    End If

    if strFormat = "Dashes" then fnFormatDate=yyyy&"-"&mm&"-"&dd

    if strFormat = "NoDash" then fnFormatDate=yyyy&mm&dd

    End Function

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply