Date format Script task

  • Hi All

    The date format is YYYYMMDD_hhmmss

    For that i have wriiten like below in script task.

    Year(Now.Date).ToString + Month(Now.Date).ToString + Day(Now.Date).ToString + "_" + Hour(Now).ToString + Minute(Now).ToString + Second(Now).ToString

    If date is 14/10/2010

    then output is 20101014_154258

    if it is 5/9/2010

    then 201095_154258

    But I want it in 20100905_154258 format.[Min and Sec are coming like this also]

    thanks

    Rohit

  • I'm not au fait with scripts but within SSIS I added the following before my month and date fields :

    ((dt_wstr,2)len((dt_wstr,2)month(getdate()))=="2"?"":"0")

    which is saying "if the month is 2 chars long do nothing else add a zero" - you might be able to adapt for your script.

  • Hi

    It can be done by following way

    Now.Date.ToString("yyyy") + Now.Date.ToString("MM") + Now.Date.ToString("dd") + "_" + Now.ToString("HH") + Now.ToString("mm") + Now.ToString("ss")

    thanks

    Rohit

  • You don't need to make it that complicated.

    Just use this:

    Now.ToString("yyyyMmdd_HHmmss")

    QUIGROUP- Need a Certified experienced DBA for a project or troubleshooting? Need help with programming, database recovery, performance tuning, ETL, SSRS or developing new databases? Contact us.. 1-786-273-9809

  • I assume you have a reason to format the date as a string in that format, but if not then you should really look into formatting in an ISO format.

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

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