Add Leading Zeros to Date Time expression?

  • This is my expression, I need to add leading zeros to cater for dates such as 01/01/2010 which appear as 201011.

    Thanks

    "DELETE

    FROM MyTable

    WHERE DATE >= '" + (DT_STR, 4, 1252) DATEPART("yyyy", @[User::CutOffDate]) +

    (DT_STR, 4, 1252) DATEPART("mm", @[User::CutOffDate]) +

    (DT_STR, 4, 1252) DATEPART("dd", @[User::CutOffDate]) + "'"

  • I'll have to guess at your question, as you have not stated one ...

    Use something like

    Right('0' + [month as Varchar], 2)


  • Apologies I have been attempting to correct this but cannot get the syntax right. I have tried to add something along the lines of RIGHT('0' + but I just cannot get the syntax in the expression builder right

  • This works - just tested it:

    RIGHT("0" + (DT_STR,4,1252)DATEPART("dd",GETDATE()),2)


  • Great, thanks for your help. I was using single quotes for the zero which was causing me an issue.

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

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