cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

parseDate giving "invalid format" error

oaslan
13-Aquamarine

parseDate giving "invalid format" error

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"

ACCEPTED SOLUTION

Accepted Solutions
Arun_C
16-Pearl
(To:oaslan)

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

View solution in original post

3 REPLIES 3
Arun_C
16-Pearl
(To:oaslan)

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

oaslan
13-Aquamarine
(To:Arun_C)

Dear Arun,

 

It worked, thank you for your support. It seems the sdf format should be properly defined.

VladimirRosu
19-Tanzanite
(To:oaslan)

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.

Announcements


Top Tags