DevLifeStyle Community

CAML Query with Time Comparison

rated by 0 users
This post has 0 Replies | 1 Follower

Top 10 Contributor
Male
Posts 115
Mohamad Halabi Posted: 04-21-2009 12:22 AM

if you are writing a CAML query to filter your list records based on date; you will basically write something like this:

<Query>
   <Where>
      <And>
         <Geq>
            <FieldRef Name='Modified' />
            <Value Type='DateTime'>2009-04-21T00:00:00Z</Value>
         </Geq>
         <Lt>
            <FieldRef Name='Modified' />
            <Value Type='DateTime'>2009-04-21T09:43:00Z</Value>
         </Lt>
      </And>
   </Where>
</Query>
The problem with the above is that it won't take time into consideration. 
It will only conside date.
so in this case you won't be able to filter based on time. a useful tip is to include the 
(IncludeTimeValue='TRUE') attribute to the (Value) tag; so that it will now read:

<Value Type='DateTime' IncludeTimeValue='TRUE'>2009-04-21T09:43:00Z</Value>

it took me some time to find this out, so hope it helps!
Page 1 of 1 (1 items) | RSS
Copyright© 2009 DevLifeStyle. All rights reserved
Powered by Community Server (Non-Commercial Edition), by Telligent Systems