Need to get two year digit only, not four this time, for a dynamic file name

  • Brad Allison

    Hall of Fame

    Points: 3473

    I know this will be easy for most, but for me I have tried a few things that are not working.  I have this from a prior job and just modified for this one in the connection string expression:

    "POMAROAK" + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + (DT_WSTR,4)DATEPART("yy",GetDate())+  ".txt"

     I need to take that yy DATEPART and return only the two digit year.  

    Thanks

    UPDATE:  As usual after I ever post something, I solve my own problem.  And this is the answer to the two year digit dilemma: RIGHT("0" + (DT_WSTR,4)DATEPART("yy",GetDate()),2)

  • Lynn Pettis

    SSC Guru

    Points: 442143

    Brad Allison - Friday, June 15, 2018 7:18 AM

    I know this will be easy for most, but for me I have tried a few things that are not working.  I have this from a prior job and just modified for this one in the connection string expression:

    "POMAROAK" + RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) + (DT_WSTR,4)DATEPART("yy",GetDate())+  ".txt"

     I need to take that yy DATEPART and return only the two digit year.  

    Thanks

    UPDATE:  As usual after I ever post something, I solve my own problem.  And this is the answer to the two year digit dilemma: RIGHT("0" + (DT_WSTR,4)DATEPART("yy",GetDate()),2)

    Do you really need to prepend the "0" before taking the RIGHT of the DATEPART?  I haven't used SSIS in quite awhile and don't have the SSIS available at the moment to test.

  • John Mitchell-245523

    SSC Guru

    Points: 148317

    Brad Allison - Friday, June 15, 2018 7:18 AM

    UPDATE:  As usual after I ever post something, I solve my own problem.  And this is the answer to the two year digit dilemma: RIGHT("0" + (DT_WSTR,4)DATEPART("yy",GetDate()),2)

    Or this, which doesn't need character conversions:
    DATEPART("yy",GetDate())%100

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

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