dateadd in the derived column transformation

  • Hi

    I have the following expression im using to create the date on the derived column:

    SUBSTRING(ReceivedOn,1,4) + "/" + SUBSTRING(ReceivedOn,5,2) + "/" + SUBSTRING(ReceivedOn,7,2) + " " + SUBSTRING(ReceivedOn,9,2) + ":" + SUBSTRING(ReceivedOn,11,2) + ":" + SUBSTRING(ReceivedOn,13,2)

    the output for the expression above is 2016/02/10 11:58 AM, I need to subtract 2 hours and the output should be 2016/02/10 09:58 AM. how do I do that.

    Thanks

  • What is the format of the date (ReceivedOn) before you parse it?

  • Hi

    The date format is 2016/02/11 07:56:15, and I need to subtract 2hrs from the time, using the expression from my previous post.

  • That doesn't make sense based on how you are parsing it. You are adding the slashes in yourself. If the output of your expression is 2016/02/11 09:56:15 then you should just be able to cast it and use DATEADD like so.

    DATEADD("Hh",-2,(DT_DBTIMESTAMP)(SUBSTRING(ReceivedOn,1,4) + "/" + SUBSTRING(ReceivedOn,5,2) + "/" + SUBSTRING(ReceivedOn,7,2) + " " + SUBSTRING(ReceivedOn,9,2) + ":" + SUBSTRING(ReceivedOn,11,2) + ":" + SUBSTRING(ReceivedOn,13,2)))

    If your output is 2016/02/10 11:58 AM, like you wrote in your first post, then it will not cast. If that is the case it would be worth looking at the input before you chop it up so we can see if that would convert easier.

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

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