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>");
7

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.

  • 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 '15 at 10:17
  • Using "Today", without including time, would look like: <Geq><FieldRef Name='vpux'/><Value IncludeTimeValue='FALSE' Type='DateTime'><Today /></Geq> – Paul Strupeikis Jun 26 '15 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 '15 at 10:23
  • 3
    Should there not be and ending </Value> tag above? – Robert Lindgren Jun 26 '15 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> – Paul Strupeikis Jun 26 '15 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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