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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

get last x Datatable entries without Stream by using timestamp field of Datatable

VaibhavShinde
16-Pearl

get last x Datatable entries without Stream by using timestamp field of Datatable

Hi ,

Looking to retrieve data from datatable using Timestamp field . I have requirement like retrieve current date data , weekly data (last 7 days) etc.  here timestamp values can be duplicated .  we want last 7 days entries from datatable. how we can do it?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Ciprian-Traian ,

I have done this requirement by using below code and it worked.

 

var days=7; // Days you want to subtract
var currentdate = new Date();
var lastDate = new Date(currentdate.getTime() - (days * 24 * 60 * 60 * 1000));
var day =lastDate.getDate();
var month=lastDate.getMonth()+1;
var year=lastDate.getFullYear();
logger.warn(lastDate);
//logger.warn(day);
var query =
{
"filters": {
"type": "Between",
"fieldName": "timestamp",
"from": lastDate,
"to": currentdate
}
};

 

Thank you

View solution in original post

4 REPLIES 4

You can use example :

 

var query =
{
    "filters": {
        "type": "Between",
        "fieldName": "timestamp",
        "from": "2",
        "to": "12"
    }
};

 

 

More info can be consulted at Query Parameter for Query Services

 

 

thank you for quick response, but here we are not giving start and end date , I don't know how many entries there are in datatable , only entries I want that are inserted in last 7 days . you can use timestamp field. 

 

Thanks

Maybe this :

 

var query =
{
    "filters": {
        "type": "GT",
        "fieldName": "timestamp",
        "value": "12"
    }
};

Hi Ciprian-Traian ,

I have done this requirement by using below code and it worked.

 

var days=7; // Days you want to subtract
var currentdate = new Date();
var lastDate = new Date(currentdate.getTime() - (days * 24 * 60 * 60 * 1000));
var day =lastDate.getDate();
var month=lastDate.getMonth()+1;
var year=lastDate.getFullYear();
logger.warn(lastDate);
//logger.warn(day);
var query =
{
"filters": {
"type": "Between",
"fieldName": "timestamp",
"from": lastDate,
"to": currentdate
}
};

 

Thank you

Top Tags