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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Get the latest Timestamp from Infotable

pshashipreetham
17-Peridot

Get the latest Timestamp from Infotable

Hi,

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

 

Thanks, 

Shashi Preetham
1 ACCEPTED SOLUTION

Accepted Solutions

hi @Velkumar ,

 

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

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

 Thanks,

Shashi Preetham

View solution in original post

3 REPLIES 3

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

Hi @pshashipreetham 

 

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

 

Velkumar_0-1682173483368.png

 

/VR

 

hi @Velkumar ,

 

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

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

 Thanks,

Shashi Preetham
Top Tags