cancel
Showing results for 
Search instead for 
Did you mean: 

Converting Varchar data into Datetime

Matt
New Contributor

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.

image

13 REPLIES 13

Ajay_Chawda
Contributor

Hi Matt
You can use Date.parse() function to convert input string to Datetime.

Date.parse(“20170604 125452”, “yyyyMMdd HHmmss”)

this will give desired output.
convertVarcharToDate_2018_12_06.slp (2.6 KB)

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

image

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?

pavan44
New Contributor III

Yes, That’s correct.