Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

New Post: Get list item count for a week

$
0
0
Another approach to using "hard" dates is to take advantage of the <Today> element and it's OffsetDays attribute... Here is a sample of code that uses the <Today> CAML element to get all items after a certain date based on an offset from "today" to the beginning of the week:

(Full disclosure: I have not tested this specific example, but have used similar one solution I have developed)
var daysFromSunday = (new Date()).getDay(),
    dateOffset = (
            daysFromSunday > 0
        ?   " OffsetDays='-" + daysFromSunday + "'"
        :   ""
    ),
    query;

var query = "<Query>" +
        "<Where>" +
            "<Gt>" +
                "<FieldRef Name='CreateDate' />" +
                "<Value Type='DateTime'>" +
                    "<Today" + dateOffset + "/>" +
                "</Value>" +
            "</Gt>" + 
        "</Where>" +
    "</Query>";
The code above, if used today - Monday - would generate a <Today> element like the following:
<Today OffsetDays='-1'/>
/Paul.

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>