CAML クエリーで、「締切日が今日以前」や「締切日が今日より 5 日前」という条件を指定する場合、今日という変数は Today タグで指定します。
また、Today タグの OffsetDays 属性で 5 日前とか 3 日後といった +- の日付を指定します。
例:締切日が今日以前
1 | <span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">Query</span><span class="kwrd">></span> |
1 | <span class="lnum"> 2: </span> <span class="kwrd"><</span><span class="html">Where</span><span class="kwrd">></span> |
1 | <span class="lnum"> 3: </span> <span class="kwrd"><</span><span class="html">Leq</span><span class="kwrd">></span> |
1 | <span class="lnum"> 4: </span> <span class="kwrd"><</span><span class="html">FieldRef</span> <span class="attr">Name</span><span class="kwrd">="DueDate"</span> <span class="kwrd">/></span> |
1 | <span class="lnum"> 5: </span> <span class="kwrd"><</span><span class="html">Value</span> <span class="attr">Type</span><span class="kwrd">="DateTime"</span><span class="kwrd">></span> |
1 | <span class="lnum"> 6: </span> <span class="kwrd"><</span><span class="html">Today</span> <span class="kwrd">/></span> |
1 | <span class="lnum"> 7: </span> <span class="kwrd"></</span><span class="html">Value</span><span class="kwrd">></span> |
1 | <span class="lnum"> 8: </span> <span class="kwrd"></</span><span class="html">Leq</span><span class="kwrd">></span> |
1 | <span class="lnum"> 9: </span> <span class="kwrd"></</span><span class="html">Where</span><span class="kwrd">></span> |
1 | <span class="lnum"> 10: </span><span class="kwrd"></</span><span class="html">Query</span><span class="kwrd">></span> |
例:締切日が今日より5日前
1 | <span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">Query</span><span class="kwrd">></span> |
1 | <span class="lnum"> 2: </span> <span class="kwrd"><</span><span class="html">Where</span><span class="kwrd">></span> |
1 | <span class="lnum"> 3: </span> <span class="kwrd"><</span><span class="html">Lt</span><span class="kwrd">></span> |
1 | <span class="lnum"> 4: </span> <span class="kwrd"><</span><span class="html">FieldRef</span> <span class="attr">Name</span><span class="kwrd">="DueDate"</span> <span class="kwrd">/></span> |
1 | <span class="lnum"> 5: </span> <span class="kwrd"><</span><span class="html">Value</span> <span class="attr">Type</span><span class="kwrd">="DateTime"</span><span class="kwrd">></span> |
1 | <span class="lnum"> 6: </span> <span class="kwrd"><</span><span class="html">Today</span> <span class="attr">OffsetDays</span><span class="kwrd">="-5"</span> <span class="kwrd">/></span> |
1 | <span class="lnum"> 7: </span> <span class="kwrd"></</span><span class="html">Value</span><span class="kwrd">></span> |
1 | <span class="lnum"> 8: </span> <span class="kwrd"></</span><span class="html">Lt</span><span class="kwrd">></span> |
1 | <span class="lnum"> 9: </span> <span class="kwrd"></</span><span class="html">Where</span><span class="kwrd">></span> |
1 | <span class="lnum"> 10: </span><span class="kwrd"></</span><span class="html">Query</span><span class="kwrd">></span> |
なお、TechNet にも Today タグの説明が載っていますが、2013/3/10 現在、オフセットを指定する属性に間違いがあります。
TechNet 上は “OffsetDays” ではなく、”Offset” となっています。
試しに “Offset” と書いてみましたが、正しく動作しませんでした。
TechNet : Today 要素(クエリ)
http://technet.microsoft.com/ja-jp/subscriptions/ms460496.aspx