Skip to main content
18-Opal
April 21, 2023
Solved

Get the latest Timestamp from Infotable

  • April 21, 2023
  • 2 replies
  • 1694 views

Hi,

 is there a way to get the latest timestamp entry from an InfoTable which has around 20 timestamps rows?

 

Thanks, 

Best answer by pshashipreetham

hi @Velkumar ,

 

Thanks for it; I am not sure how I missed it.

let sort = {
 name: "timestamp",
 ascending: false
};
result.Sort(sort);

 Thanks,

2 replies

17-Peridot
April 21, 2023

Hello @pshashipreetham,

 

Here is some code that should do what you want:

 

// if your dates are strings
let objects = [
 { date: "2023-04-19" },
 { date: "2023-04-20" },
 { date: "2023-04-21" },
];

let newestDate = new Date(
 Math.max.apply(
 null,
 objects.map(function (obj) {
 return Date.parse(obj.date);
 })
 )
);

result = newestDate.toDateString(); // Output: Fri Apr 21 2023

// if your dates are dates
let objects = [
 { date: new Date("2023-04-19T12:00:00Z") },
 { date: new Date("2023-04-20T12:00:00Z") },
 { date: new Date("2023-04-21T12:00:00Z") },
];

let newestDate = new Date(Math.max.apply(null, objects.map(function(obj) {
 return obj.date.getTime();
})));

result = newestDate.toDateString(); // Output: Fri Apr 21 2023

 

Hope this helps.

 

Regards,

Jens

19-Tanzanite
April 22, 2023

Hi @pshashipreetham 

 

You can use the 'Sort' snippet to sort rows in InfoTable 

 

Velkumar_0-1682173483368.png

 

/VR

 

pshashipreetham18-OpalAuthorAnswer
18-Opal
May 9, 2023

hi @Velkumar ,

 

Thanks for it; I am not sure how I missed it.

let sort = {
 name: "timestamp",
 ascending: false
};
result.Sort(sort);

 Thanks,