Skip to main content
1-Visitor
January 25, 2022
Question

parseDate is not working

  • January 25, 2022
  • 1 reply
  • 2345 views

Hello, need some help.

 

I want a service Datetime output(string works) with ""MM/DD/YYYY hh:mm" format, I used dateFormat and parseDate to try to achieve this, but output shows other format, I check with postman, and I looks similar, please help.

 

AZ_10002894_0-1643148478687.png

postman

AZ_10002894_1-1643148599069.png

 

 

1 reply

5-Regular Member
January 26, 2022

Hi @AZ_10002894 ,

 

Kindly check the following article on parsedate in Thingworx:

https://www.ptc.com/en/support/article/CS219448

 

Let me know if it doesnt solve your issue.

 

Regards

Bhawna

1-Visitor
January 26, 2022

Hello Bhawna,

 

that was exactly example that I used, just eliminate sdf var, using the string directly in parseString and parseDate.

//Standard ThingWorx Date Format
var sdf = "MM/DD/YYYY hh:mm";

// dateValue:DATETIME
var dateValue = new Date();

// dateFormat(dateValue:DATETIME,dateFormat:STRING):STRING
var formattedDate = dateFormat(dateValue, sdf);

// parseDate(stringDate:STRING,dateFormat:STRING):DATETIME
var result = parseDate(formattedDate, sdf);

 

but, that doesnot works, at least for me, could you run this code on a thingworx service?, that doesnt change the output format.

5-Regular Member
January 27, 2022

Hello @AZ_10002894 ,

 

why don't you get the output as string and provide formatted date into output instead of parsing it?

 

// dateFormat(dateValue:DATETIME,dateFormat:STRING):STRING
var formattedDate = dateFormat(dateValue, sdf);

 

// parseDate(stringDate:STRING,dateFormat:STRING):DATETIME
//var result = parseDate(formattedDate, "MM-dd-yyyy HH:MM");
var result = formattedDate;

 

pls let me know if you need further assistance on this or if it doesn't meet your use case.

 

Regards

Bhawna