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

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

SOLVED
Highlighted
Moonstone

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
Highlighted

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

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
Highlighted

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

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

 

 

Highlighted

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

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

Highlighted

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

Maybe this :

 

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

Highlighted

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

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

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum!