Mahozad
Mahozad

Reputation: 24502

How to use parameter in strftim() function in sqlite

I'm using Room library in an android project. How can I use the method parameter in strftime() function (something like :period days instead of 7 days)?

@Query("SELECT * FROM purchase " +
        "WHERE date >= strftime('%s', 'now', 'localtime', 'start of day', '7 days')")
List<Purchase> getPurchases(int period);                               \\ ☝ //

Upvotes: 0

Views: 35

Answers (1)

Shawn
Shawn

Reputation: 52344

With string concatenation:

strftime('%s', 'now', 'localtime', 'start of day', :period || ' days')

Upvotes: 1

Related Questions