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

anivtk
New Contributor II

I am calling the snapLogic Activity API and its returning the date in the format as โ€œ2020-02-21T17:44:19.996000+00:00โ€

I am trying to store this data into SQL server and SQL server doesnโ€™t accept this data in DateTime data type. I tried to use some simple pare method and itโ€™s still not accepting. Later I used some complex Parse method like below, but its still not working.

Date.parse($create_time,โ€œyyyy-MM-ddโ€™Tโ€™HH:mm:ss.SSSSSSXโ€).toLocaleDateTimeString({โ€œformatโ€:โ€œyyyyMMdd-HHmmssโ€})

Can someone provide how to parse the data in this format โ€œ2020-02-21T17:44:19.996000+00:00โ€ to DateTime which is compatible with SQL server ?

I believe you just need:
Date.parse($create_time).toLocaleDateTimeString({"format":"yyyyMMdd-HHmmss"})


Diane Miller
Community Manager

anivtk
New Contributor II

Awesome, this worked! Thanks for your quick help.

Note: Inorder to insert that into SQL server I have changed the output to a format SQL server supporst. So the parse function I used is Date.parse($create_time).toLocaleDateTimeString({โ€œformatโ€:โ€œyyyy-MM-ddโ€™Tโ€™HH:mm:ss.SSSSSSโ€})

Thanks again!

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?