Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
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.
postman
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
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