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

Get Date (yyyy-MM-dd) in DateTime format

VaibhavShinde
15-Moonstone

Get Date (yyyy-MM-dd) in DateTime format

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

1 ACCEPTED SOLUTION

Accepted Solutions
c_lowy
13-Aquamarine
(To:VaibhavShinde)

@VaibhavShinde,

 

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.

View solution in original post

4 REPLIES 4
c_lowy
13-Aquamarine
(To:VaibhavShinde)

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.

VaibhavShinde
15-Moonstone
(To:c_lowy)

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

tdixit
13-Aquamarine
(To:VaibhavShinde)

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

 

c_lowy
13-Aquamarine
(To:VaibhavShinde)

@VaibhavShinde,

 

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.

View solution in original post

Announcements