3

I want to get all items from the list, which has a start date from date.now or later in time.

This is what I thought would work:

var dateNow = Date.now();

 var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml(
    "<View>" +
    "<Query>" +
    "<Where>" +
    "<And>" +
    "<Eq><FieldRef Name='Title'/><Value Type='Text'>" + txtForNamn.value +</Value></Eq>" +
    "<Geq><FieldRef Name='vpux'/><Value Type='DateTime'>" + dateNow + "</Value></Geq>" +
    "</And>" +
    "</Where>" +
    "</Query>" +
    "</View>");

1 Answer 1

10

Replace

<Geq>
   <FieldRef Name='vpux'/>
   <Value Type='Text'>" + dateNow + "</Value>
</Geq>

with

<Geq>
    <FieldRef Name='vpux'/>
    <Value IncludeTimeValue='TRUE' Type='DateTime'><Now /></Value>
</Geq>

You can use <Today /> as well. IncludeTimeValue is, obviously, for including time in the query.

6
  • how does it look like when using "<today />"? I don't think I want to include time. Thank you for helping me!
    – Dr Cox
    Jun 26, 2015 at 10:17
  • Using "Today", without including time, would look like: <Geq><FieldRef Name='vpux'/><Value IncludeTimeValue='FALSE' Type='DateTime'><Today /></Geq> Jun 26, 2015 at 10:18
  • now it says "Error. Cannot complete this action.", I get the same when I'm trying to get from an earlier date :/
    – Dr Cox
    Jun 26, 2015 at 10:23
  • 3
    Should there not be and ending </Value> tag above? Jun 26, 2015 at 10:53
  • 1
    Thanks! Missed that one. The query with "Today" should look like this: <Geq><FieldRef Name='vpux'/><Value IncludeTimeValue='FALSE' Type='DateTime'><Today /></Value></Geq> Jun 26, 2015 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.