Query database now minus 14 days

Hi.

I want to query the recent changes of the last 14 days. I have no idea, how I can set this date in the query with “$now - 14 days”.

#set ($void = $services.async.useEntity("wiki:$xcontext.database"))
#set ($query = $services.query.xwql("select doc.fullName, doc.language, doc.date from Document doc where doc.date > :date order by doc.date desc"))
#set ($recentDocs = $query.bindValue('date', $datetool.toDate('yyyy-MM-dd', '2022-07-16')).addFilter('unique').setLimit(100).execute())

I can set it a coded date as above (‘2022-07-16’) but I couldn’t find a working way to script my idea.
Any hints?

Regards, Simpel

I found a solution inspired by the “Date” Calculations snippet.
It now looks like this:

    #set ($calendar = $datetool.systemCalendar)
    #set ($discard = $calendar.add(5, -13))
    #set ($dateBefore14Days = $calendar.time)
    #set($date = $xwiki.formatDate($dateBefore14Days, "yyyy-MM-dd"))

    #set ($void = $services.async.useEntity("wiki:$xcontext.database"))
    #set ($query = $services.query.xwql("select doc.fullName, doc.language, doc.date from Document doc where doc.date > :date order by doc.date desc"))
    #set ($recentDocs = $query.bindValue('date', $datetool.toDate('yyyy-MM-dd', $date)).addFilter('unique').setLimit(1000).execute())

Attention: as today counts as day 1 for me 14 days is “today until 13 day backwards”.