Format Date in Script Task problem

  • Not sure what is going on, I have the following variable:

    Dim fileDate As String = Format(Today(), "yyyymmdd")

    but returns '20100012', what happen to the month part? It's 00 and not 07.

    I put in

    Dim fileDate As Date = Today()

    returns '7/12/2010' (can't use this because of /)

    I even do

    Dim fileDate As String = year(today()) & month(today()) & day(today())

    retursn '2010712' (can't use this because I need the 0 in front of the 7)

    This is a simple task what am I missing?

    Thanks!

  • Try this. I did not test it, but it might work

    Dim fileDate As String = year(today()) &"0" & month(today()) & day(today())

    OR

    IF month(today()) < 9

    Dim fileDate As String = year(today()) &"0" & month(today()) & day(today())

    ELSE

    Dim fileDate As String = year(today()) & month(today()) & day(today())

  • That worked, guess I was looking through a narrow scope.

    Thanks! 🙂

  • You'll have a problem with September if you use that code verbatim!

    <= 9 works better 🙂

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • True, I had noticed that and fixed it with < 10.

    Thanks I should have commented on that.

  • Phil Parkin (7/13/2010)


    You'll have a problem with September if you use that code verbatim!

    <= 9 works better 🙂

    Thanks for correcting it 😉

Viewing 6 posts - 1 through 5 (of 5 total)

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