Skip to main content
14-Alexandrite
July 28, 2024
Solved

parseDate giving "invalid format" error

  • July 28, 2024
  • 2 replies
  • 1580 views

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"

Best answer by 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

2 replies

Arun_C16-PearlAnswer
16-Pearl
July 29, 2024

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

oaslan14-AlexandriteAuthor
14-Alexandrite
July 29, 2024

Dear Arun,

 

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

19-Tanzanite
July 29, 2024

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.