2

I'd like to perform a SMW query based on current year and month information. The problem: It seems that I need to feed values into the SMW ask section in a non-static way as I cannot hard code these values. How can I do that and perform such a query?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Regis May
  • 3,070
  • 2
  • 30
  • 51

2 Answers2

2

Use {{#time:}} parser function. Date formats that SMW will understand are given here. Below, I used d.m.Y and d xg Y that will definitely work in a wiki in Russian.

Use Unix format (U, the number of seconds since Unix era; use @ to convert it back to date object) for date arithmetics.

Examples (assuming that you have the special property Creation date activated):

<!-- Pages created today -->
{{#ask:
[[Creation date::>={{#time:d.m.Y}}]]
}}

<!-- Pages created yesterday -->
{{#ask:
[[Creation date::>={{#time:d xg Y|@{{#expr:{{#time:U}}-86400}}}}]]
[[Creation date::<{{#time:d xg Y}}]]
}}

Alexander Mashin
  • 3,892
  • 1
  • 9
  • 15
2

You can also use the MediaWiki magic words https://www.mediawiki.org/wiki/Help:Magic_words/de e.g.

{{#ask:
[[Modification date::>={{CURRENTYEAR}}-{{CURRENTMONTH}}-{{CURRENTDAY2}}]]
}}
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186