Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi,
I have two date values in String format like "2024-07-25 19:41:27.0000000 +00:00"
I want to calculate the time difference in between so I want to change them to date format. so used the code below but it gives me the invalid format error. Parsing neglects the year:
let StartDate = "2024-07-25 19:41:27.0000000 +00:00"
let sdf = "yyyyMMddHHmmsszzz";
result = parseDate(StartDate,sdf);
Invalid format: "2024-07-25 19:41:27.0000000 +00:00" is malformed at "-07-25 19:41:27.0000000 +00:00"
I even tried the slice the string, but I got the same error:
let StartDate = "2024-07-25 19:41:27.0000000 +00:00"
let ShortStartDate = StartDate.slice(0,19)
let sdf = "yyyyMMddHHmmsszzz";
result = parseDate(ShortStartDate,sdf);
Invalid format: "2024-07-25 19:41:27" is malformed at "-07-25 19:41:27"
Solved! Go to Solution.
HI @oaslan ,
Kindly find the below attached date conversion code which working for me.
let StartDate = "2024-07-25 19:41:27.0000000 +00:00";
let ShortStartDate = StartDate.slice(0,19);
///**// DateTime Format ///**///
let sdf = "yyyy-MM-dd HH:mm:ss";
result = parseDate(ShortStartDate,sdf);
Thanks & Regards,
Arun C
HI @oaslan ,
Kindly find the below attached date conversion code which working for me.
let StartDate = "2024-07-25 19:41:27.0000000 +00:00";
let ShortStartDate = StartDate.slice(0,19);
///**// DateTime Format ///**///
let sdf = "yyyy-MM-dd HH:mm:ss";
result = parseDate(ShortStartDate,sdf);
Thanks & Regards,
Arun C
Dear Arun,
It worked, thank you for your support. It seems the sdf format should be properly defined.
It's probably good to know that the parseDate uses the format from the Joda library and examples can be seen here:
https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html
Note there are a few articles related to parseDate in the support.ptc.com, and specifically this one explains how to use it and links to the site above.