locked
Caml Query regarding DateTime RRS feed

  • Question

  • Hi

    I want to fetch items from List based on modified date..Say for eg:I need to the get name of the people who have not modified in the list for past 1 month.I was trying to get that but i was not able to succeed.
    So i wrote a query which will pull users who have modified in the list for past 1 month

    "<Where><And><And><Geq><FieldRef Name='Modified' /><Value Type='DateTime'><Today OffsetDays='-30'/></Value></Geq><IsNull><FieldRef Name='SecondReminder' /></IsNull></And><Eq> <FieldRef Name='FirstReminder' /><Value Type='Boolean'>1</Value></Eq> </And></Where>"

    I m storing the above result in the Arraylist.I m using some logic to get the remaining users by comparing to the list item.

    My requirement is to get the users who have not modified anything in the list for past 1 month using caml query.Is this Possible..Pls help

    Thanks,
    Anu

    Wednesday, June 3, 2009 11:31 AM

Answers

  • I'm not sure, but I think that the query should be a <Leq> instead of <Geq> for the Modified date comparison. If I understand your filter expression well, you are looking for the Modified dates that are older than the last 30 days, right?

    -- Edin http://edinkapic.blogspot.com
    Wednesday, June 3, 2009 11:53 AM
  • Your query should be like,


    <Query>
       <Where>
          <Leq>
             <FieldRef Name='Modified' />
             <Value Type='DateTime'><Today OffsetDays='-30'/></Value>
          </Leq>
       </Where>
    </Query>





    Regards
    Ashraf ul Islam
    Sharepoint Consultant

    • Marked as answer by Anu Pravinya Friday, June 26, 2009 5:14 AM
    Wednesday, June 3, 2009 12:52 PM

All replies

  • I'm not sure, but I think that the query should be a <Leq> instead of <Geq> for the Modified date comparison. If I understand your filter expression well, you are looking for the Modified dates that are older than the last 30 days, right?

    -- Edin http://edinkapic.blogspot.com
    Wednesday, June 3, 2009 11:53 AM
  • Thanks for your reply.
    yep ...i m looking for datas older than 30 days
    Wednesday, June 3, 2009 12:11 PM
  • Your query should be like,


    <Query>
       <Where>
          <Leq>
             <FieldRef Name='Modified' />
             <Value Type='DateTime'><Today OffsetDays='-30'/></Value>
          </Leq>
       </Where>
    </Query>





    Regards
    Ashraf ul Islam
    Sharepoint Consultant

    • Marked as answer by Anu Pravinya Friday, June 26, 2009 5:14 AM
    Wednesday, June 3, 2009 12:52 PM
  • Hi,

    I think that the answer from Edin is correct, but if you have items modified in the past month too, and get no item back from your query then probably your query might has other problems too.

    I suggest to debug your query step by step, build it up from simple to more complex logic to identify the source of the problem.

    You can use tools like CAML query builder (http://www.u2u.be/res/Tools/CamlQueryBuilder.aspx) or CAML.NET (http://camldotnet.com/) to build (and test) your CAML queries in a user (I mean developer) friendly way and with less errors.

    As I see the CAML.NET site is not really working now on 100%, but I saw earlier version of this tool and it was very impressing (http://www.johnholliday.net/post/2007/07/19/Working-with-CAMLNet-Part-2-Introducing-the-CAML-Query-Designer-.aspx).

    Peter
    Wednesday, June 3, 2009 1:03 PM
  • Hi Anu,

    Have your problem been solved?

    If no where are you running your queries from? From object model (SPQuery) or through the Lists webs service? In the second case you need the <Query> tag as Ashraf wrote, otherwise not.

    Peter

    Friday, June 5, 2009 9:32 AM
  • Thanks a lot....It helped me a lot...Got into Project issue...So could not reply soon
    Once again thanks to all

    -Anu
    Friday, June 26, 2009 5:13 AM
  • Not at all! I am happy that Edin and Ashraf could help you to solve your problem.

    Peter
    Friday, June 26, 2009 6:08 AM