Skip to main content
Level 5
Apr 4, 2023 10:43 AM UTC
Solved

Datetime format in JSSP for dd-mm-yyyy

Hi Everyone,

We are encountering an issue regarding datetime in our current solution in both JSSP and Workflow. We are receiving "dd-mm-yyyy hh:mm:ss". However, it seems parsetimestamp or any other functions which is capable to format such datetime data.

Can anyone suggest how to use any javascript function to get timestamp from the above formatted data.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Marcel_Szimonisz
Marcel_SzimoniszAccepted solution
Community Advisor
Apr 5, 2023 8:43 AM UTC

Hello @supratim320 ,

i thought Date can parse date in any format but somehow DD-MM-YYYY is not one the formats it accepts. Same goes for the JSAPI function parseDateTime it accepts only ISO 8601 date strings.

You can still do a simple mapping:

 

var dateString = '05-04-2023 10:30:00', parts = dateString.split(' '), dateParts = parts[0].split('-'), timeParts = parts[1].split(':'), year = parseInt(dateParts[2], 10), month = parseInt(dateParts[1], 10) - 1, day = parseInt(dateParts[0], 10), hours = parseInt(timeParts[0], 10), minutes = parseInt(timeParts[1], 10), seconds = parseInt(timeParts[2], 10), date = new Date(year, month, day, hours, minutes, seconds); logInfo(date); var df = formatDate(date,"%4Y-%2M-%2D %02H:%02N:%02S"); logInfo(df); //04/05/2023 4:39:10 AM js 2023-04-05 10:30:00 //04/05/2023 4:39:10 AM js Wed Apr 05 2023 10:30:00 GMT-0400 (EDT)

 

 
Although I would recommend sending already preformatted date in ISO 8601, from the source system if it is possible 


Marcel Szimonisz

8 replies

david--garcia
Level 10
Apr 4, 2023 10:50 AM UTC

Whats your requirement?

 

Show current output and expected output.

Translate
https://www.linkedin.com/in/david-garcia-uk/ | https://martech.network
Level 5
Apr 4, 2023 1:14 PM UTC

Hi @david--garcia , I am unable to save this data in Database.

Sample input as string column: "15-12-2023 05:40:15" (dd-mm-yyyy hh:mi:ss)

When I am running as: formatDate(orderDate,"%4Y-%2M-%2D %02H:%02N:%02S"), error: "invalid character at position 5 ('3')"

 

However, if I change datetime into: "2023-12-15 05:40:15" (yyyy-mm-dd hh:mi:ss), formatDate(orderDate,"%4Y-%2M-%2D %02H:%02N:%02S") works.

So, my question is: how can I save a date format which is received as: dd-mm-yyyy hh:mi:ss

 

Translate
Marcel_Szimonisz
Community Advisor
Community Advisor
Apr 4, 2023 6:38 PM UTC

Hello @supratim320 ,

you can use native JavaScript functionality to parse string into date:

 

var d = new Date("15-12-2023 05:40:15");//native JS formatDate(d,"%4Y-%2M-%2D %02H:%02N:%02S")//adobe campaign jsapi

 

 

Marcel

Translate
Level 5
Apr 5, 2023 2:44 AM UTC

Thank you for the update @marcel_szimonisz , but this output to me as: "0000-01-00 20:00:00".

Translate
Marcel_Szimonisz
Community Advisor
Community Advisor
Apr 5, 2023 6:34 AM UTC

Can you logInfo the date created from new date()?

Translate
Marcel_Szimonisz
Community Advisor
Marcel_SzimoniszCommunity AdvisorAccepted solution
Community Advisor
Apr 5, 2023 8:43 AM UTC

Hello @supratim320 ,

i thought Date can parse date in any format but somehow DD-MM-YYYY is not one the formats it accepts. Same goes for the JSAPI function parseDateTime it accepts only ISO 8601 date strings.

You can still do a simple mapping:

 

var dateString = '05-04-2023 10:30:00', parts = dateString.split(' '), dateParts = parts[0].split('-'), timeParts = parts[1].split(':'), year = parseInt(dateParts[2], 10), month = parseInt(dateParts[1], 10) - 1, day = parseInt(dateParts[0], 10), hours = parseInt(timeParts[0], 10), minutes = parseInt(timeParts[1], 10), seconds = parseInt(timeParts[2], 10), date = new Date(year, month, day, hours, minutes, seconds); logInfo(date); var df = formatDate(date,"%4Y-%2M-%2D %02H:%02N:%02S"); logInfo(df); //04/05/2023 4:39:10 AM js 2023-04-05 10:30:00 //04/05/2023 4:39:10 AM js Wed Apr 05 2023 10:30:00 GMT-0400 (EDT)

 

 
Although I would recommend sending already preformatted date in ISO 8601, from the source system if it is possible 


Marcel Szimonisz

Translate
ParthaSarathy
Community Advisor
Community Advisor
Apr 5, 2023 8:45 AM UTC

Hi @supratim320 ,

Try the below script

var orderDate = "15-12-2023 05:40:15"; var yyyymmddFormat = orderDate.substr(6,4)+"-"+orderDate.substr(3,2)+"-"+orderDate.substr(0,2)+orderDate.substr(10,9); var formatedOrderDate = formatDate(yyyymmddFormat,"%4Y-%2M-%2D %02H:%02N:%02S");

Hope this helps!

Translate
~  ParthaSarathy S~  Click here to join ADOBE CAMPAIGN USER GROUP for Quarterly In-person | Hybrid | Virtual Meetups