Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Hi ,
I am looking to display date in format yyyy-MM-dd , but returned type should be DateTime.
var d=new Date();
// dateFormat(dateValue:DATETIME, dateFormat:STRING):STRING
var formattedDate = dateFormat(d, "yyyy-MM-dd");
// parseDate(stringDate:STRING, dateFormat:STRING):DATETIME
var dateValue = parseDate(formattedDate, "YYYY-MM-DD");
but its returning Date with Time. I need only YYYY-MM-DD.
Thanks
Solved! Go to Solution.
If your goal is to use that timestamp as input to filtering data, and because a DateTime object will always have the time component as stated before, I believe you will need to call a time range in your JavaScript service filtering the data. For example take your timestamp looking something like 2021-13-04 00:00:00.000 and from there create a time range from that time until 2021-13-04 23:59:59.000 and use that to filter your data.
Hi @VaibhavShinde,
A JavaScript Date object will always have a time component and so does the ThingWorx DateTime format I believe. Depending on your intent could you consider formatting the Date at mashup level ? When displaying a date in a widget like DateTime or Value Display you can format it the way you want at runtime.
Hi @c_lowy ,
Thanks for reply, I am looking to fetch records for that day( irrespective of time) . consider i have table with "datetime" column so it stores in format 'yyyy-MM-dd hh:mm:ss'.
now i want to fetch all records for the day (Current date).
Hope you got my requirement.
Thanks
Hello @VaibhavShinde
As stated by @c_lowy ThingWorx DATETIME object will always have a time component
But, if you want the string representation of your date then you could use below code(dateValue is of type DATETIME): Output will be of Type "String" not DateTime
var result = dateFormatISO(dateValue).substr(0,10);
I have attached the sample entity for your reference
Regards,
Toolika Dixit
If your goal is to use that timestamp as input to filtering data, and because a DateTime object will always have the time component as stated before, I believe you will need to call a time range in your JavaScript service filtering the data. For example take your timestamp looking something like 2021-13-04 00:00:00.000 and from there create a time range from that time until 2021-13-04 23:59:59.000 and use that to filter your data.