Skip to main content
1-Visitor
April 16, 2020
Question

DATE from TIMESTAMP

  • April 16, 2020
  • 7 replies
  • 4549 views

Hi 

I am converting timestamp to datetime format with basetype DATETIME with the code "var date = new Date(Timestamp * 1000)". The result of it is being saved in an datafield of DATETIME basetype. I want to extract the date part of the result since i want to apply aggregate function on it. To extract the date part of the column, I am using (getFullYear(),getMonth(), getDay()) methods. But it gives me an error "Cant find getFullYear() function in "Wed Jan 15 2020 06:26:30 GMT+0530 (IST) "" Even though my DATETIME is being stored in the format YYYY/MM/DD HH:MM:SS why is it pointing to the GMT format to extract the DATE object

A way aorund it would highly be appreciated

 

regards

 

 

7 replies

16-Pearl
April 16, 2020

Woks fine for me using, for example: 

me.date1 = new Date(1579069590 * 1000);
var result = me.date1.getFullYear();

 

Could you please share your full code? Also, what is the ThingWorx version that you are using?

ketanaga1-VisitorAuthor
1-Visitor
April 16, 2020
for(i = 0; i<result.getRowCount(); i++){
 var date = new Date(result.rows[i].Timestamp * 1000);
 var year = date.getFullYear();
 var month = date.getMonth();
 var day = date.getDay();
 result.rows[i].Timestamp = year+'-'+month+'-'+day;

This is the code I am using I am getting the timestamp from csv file which I am reading and converting it into DATETIME in the same infotable under Timestamp datafield.

I am using 8.3.3 version

16-Pearl
April 16, 2020

What is the data type of the Timestamp field of the datashape on which the result infotable is based upon?

 

I am still unable to replicate it. If you just want a string representation of your date then you could use below code(dateValue is of type DATETIME): 

 

var result = dateFormatISO(dateValue).substr(0,10);