1

I have the following CAML:

<Where>
    <And>
        <Eq>
            <FieldRef Name='Author' LookupId='TRUE' />
            <Value Type='User'>473</Value>
        </Eq>
        <Eq>
            <FieldRef Name='Datum' />
            <Value Type='DateTime'>2015-06-05T00:00:00Z</Value>
        </Eq>
    </And>
</Where>

In my list I have 8 items, 7 of these have Author equals 473 and 2 of these have Datum equals 2015-06-05. Whatever value I pass to the Datum i always get 7 items. What is wrong?

5
  • Are you certain that Datum is the internal name of the column? Otherwise it looks correct. Commented Jun 5, 2015 at 14:35
  • Yes it is... shouldn't thorw it an exception otherwise? Commented Jun 5, 2015 at 14:42
  • try this one <Value IncludeTimeValue='TRUE' Type='DateTime'>2015-06-05T00:00:00</Value> Commented Jun 5, 2015 at 14:49
  • Nope. The curious thing is that I get 7 items....if the passed date value isn't correct, I should get 0 items. Right? Commented Jun 5, 2015 at 14:51
  • It tends to ignore the CAML if the field values aren't correct rather than throwing any error. I'd try downloading the BIWUG CAML Designer and see what it spits out after constructing the query. biwug.be/resources Commented Jun 5, 2015 at 15:00

3 Answers 3

1

I wasn't able to find out the problem, but with the following workaround I got it:

<Where>
<And>
    <Eq>
        <FieldRef Name='Author' LookupId='TRUE' />
        <Value Type='User'>473</Value>
    </Eq>
    <And>
        <Leq>
            <FieldRef Name='Datum' />
            <Value Type='DateTime'>2015-06-05 00:00:00</Value>
        </Leq>
        <Geq>
            <FieldRef Name='Datum' />
            <Value Type='DateTime'>2015-06-05 00:00:00</Value>
        </Geq>
    </And>
</And>

0

Please check the time zone of your server. It is possible that your web time zone and browser time zone differs. You should try these options:

  1. Set property SP.CamlQuery.datesInUtc to false
  2. Set property SP.CamlQuery.datesInUtc to true and pass correct value in UTC. For example, if your web time zone is +2 UTC, browser shows date value 2015-06-05 00:00:00, but real value in SharePoint database is 2015-06-04 22:00:00

Play with this settings and values.

1
  • I tryied it out, but the result does not change. Commented Jun 8, 2015 at 6:18
0

You can use LocalTime to UTC convertion. Example in pnp js:

const yourDateTime = new Date();
const timezone = sp.web.regionalSettings.timeZone;
const dateTimeForCaml = (await timezone.localTimeToUTC(yourDateTime)).toString();

Its solve my issue even when I have time zone differences with SharePoint.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.