简体   繁体   中英

How to do a query between date using jQuery SPServices CAMLQuery

I have some trouble retrieving items from a list where the program should retrieve the list of items with a certain range of dates provided by the user.

Here is my sample code:

function getItems(startDate, endDate){
    var query =
        "<Query>" +
            "<Where>" +
                "<And>" +
                    "<Eq>" +
                        "<FieldRef Name='Date' /><Value Type='Date'>" + > startDate + "</Value>" +
                    "</Eq>" +
                    "<Eq>" +
                        "<FieldRef Name='Date' /><Value Type='Date'>" + < startDate + "</Value>" +
                    "</Eq>" +
                "</And>" +
            "</Where>" +
            "<OrderBy>" +
                "<FieldRef Name='Start' Ascending='false' />" +
            "</OrderBy>" +
        "</Query>";

    $().SPServices......
}

Sorry it took me time to figure it out but i finally did it.

function getItems(startDate, endDate){
    var query =
        "<Query>" +
            <Where>" +
                "<And>" +
                    "<Geq>" +
                         "<FieldRef Name=\"Start\" />" +
                         "<Value Type=\"DateTime\">" + fromdate + "</Value>" +
                    "</Geq>" +
                    "<Leq>" +
                         "<FieldRef Name=\"Start\" />" +
                         "<Value Type=\"DateTime\">" + todate + "</Value>" +
                    "</Leq>" +
                "</And>" +
            "</Where>" +
            "<OrderBy>" +
                "<FieldRef Name='Start' Ascending='false' />" +
            "</OrderBy>" +
        "</Query>";
   $().SPServices......
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM