cancel
Showing results for 
Search instead for 
Did you mean: 

Filter on date using variable

roger_beach
Participant
0 Kudos

I have a variable for a date that is 60 days old called date60days.  I want to filter out any frequently used items from the launchpad gateway service where the last used date is greater than 60 days.  I am unsure how to utilize the variable in my filter.  I have tried the following:

$filter=myLastUsed gt datetime'" + date60days + "'&$orderby=myLastUsed desc",

I was able to do this in the javascript itself by using a condition on the for loop when adding the links as follows:

if (ostaticlinks[i].myLastUsed > date60days ) {

however, I'd rather filter this upfront rather than retrieving so much data from the backend.  Do I just not have the syntax correct for the $filter?

Accepted Solutions (0)

Answers (4)

Answers (4)

kammaje_cis
Active Contributor
0 Kudos

I do not think you should build the oData URL on your own, rather make use of SAPUI5 APIs. I am assuming that you are using SAPUI5.

You can create a filter instance using belowAPIs and use this instance while binding or making oData call.

SAPUI5 SDK - Demo Kit

SAPUI5 SDK - Demo Kit

How to use it

Former Member
0 Kudos

Hi Roger,

It's not clear from the above if your URI actually functions properly with the filtering. Do you have an example of a working URI string?

Before commiting to any expressions that result from a coded algorithm, I would make certain that what I think my result will be would work. So simply test that with a REST client. If that does work, you need to focus on your formatting through code where date60days is supposed to result in a formatted date. If it doesn't work in a client, there could be various causes (for one, filters need specific filter case handlers in most implementations, don't assume it will "just work").

Your URI string should be escaped as well if escaping of requests is not implicit in your client framework. 


Regards


Ron.

AshwinDutt
Active Contributor
0 Kudos

Hello Roger,


With the correct ABAP Type ( Date - YYYYMMDD ) , Sample URL would be ?$filter=myLastUsed gt gt datetime'2013-10-01T00:00:00.00'

You will get Date as shown below.

Kindly Try this. It should work.

Regards,

Ashwin




Former Member
0 Kudos

Hi Roger,

is variable date60days in this expected format 2014-05-14T15:08:40 ?

Regards,

Peter

roger_beach
Participant
0 Kudos

I had questioned that myself.  date60days is simply a date object.

I thought perhaps I needed to replace date60days with something like date60days.toISOString() but that has a format like 2014-05-14T13:13:48.797Z which is close but not exactly the same.....

ChandraMahajan
Active Contributor
0 Kudos

See this thread on stackoverflow OData: Date "Greater Than" filter - Stack Overflow

you can try with javascript function which will return date in edm format 2014-05-14T00:00:00

and then use it.

Regards,

Chandra