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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

parseDate is not working

AZ_10002894
5-Regular Member

parseDate is not working

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

 

 

3 REPLIES 3

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

AZ_10002894
5-Regular Member
(To:bchaudhary)

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.

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

Announcements


Top Tags