Forum Discussion

Matt's avatar
Matt
New Contributor
7 years ago

Converting Varchar data into Datetime

Hi everyone,

I’ve been trying to convert data I’m receiving from a varchar (20171211 125023) into a datetime (2017-12-11 12:50:23). I’ve been messing with the mapper but I feel like I’m at a road block now. I was wondering if someone in the community has any success in this.

13 Replies

  • pavan44's avatar
    pavan44
    New Contributor III

    Hi Matt,

    You can try with the below expression in your mapper. Hope this helps

    Date.parse(“20170617 125254”,“yyyyMMdd hhmmss”).toLocaleDateTimeString({“format”:“yyyy-MM-dd hh:mm:ss”})

    The output value will be

    • Matt's avatar
      Matt
      New Contributor

      Hey Pavan,

      Thank you for the reply, I just have a quick question. If I have a input scheme for example $DATE that’s bringing in data, would I just replace “20170617 125254” with the schema?

  • Ramit's avatar
    Ramit
    New Contributor

    Hi, This thread was very helpful as I was facing the same issue - I have another question, what to do if we want to pass null values in this same format?