Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In the code sample below, how should I change it to take a date range in a CAML query?

    string FullQueryUrlap = "<Where><And><Geq><FieldRef Name='{0}' /><Value IncludeTimeValue='TRUE' Type='DateTime'>{1}</Value></Geq><And><Leq><FieldRef Name='{2}' /><Value IncludeTimeValue='TRUE' Type='DateTime'>{3}</Value></Leq><Eq><FieldRef Name='Nazwisko' /><Value Type='Note'>{4}</Value></Eq></And></And></Where>";
        string dateISO1 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToLocalTime());
        Convert.ToDateTime(dateISO1);

        int spacja = DropDownList1.SelectedItem.Text.IndexOf(" ");

        var queryPoszczegolnyUrlop = new SPQuery();
        queryPoszczegolnyUrlop.Query = String.Format(FullQueryUrlap, "DataPoc", dateISO1, "DataKon", dateISO1, DropDownList1.SelectedItem.Text.ToUpper().Substring(0, spacja));
        queryPoszczegolnyUrlop.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='DataPoc' /><FieldRef Name='DataKon' />";
        queryPoszczegolnyUrlop.ViewFieldsOnly = true;

        SPListItemCollection listaDniUrlopow = witryna1.Lists["ListaUrlopow2012"].GetItems(queryPoszczegolnyUrlop);

        DateTime dataPoc= new DateTime();
        DateTime dataKon = new DateTime();

        DateTime theDate = e.Day.Date;

        for (int interator = 0; interator < listaDniUrlopow.Count; interator++)
        {
            SPListItem item = listaDniUrlopow[interator];
            dataPoc = Convert.ToDateTime(item["DataPoc"]);
            dataKon = Convert.ToDateTime(item["DataKon"]);

The debbuger told me that listaDniUrlopow.Count have got 0 elements. Please help. When I giving that query string FullQueryUrlap = "<Where><And><Eq><FieldRef Name='{0}' /><Value Type='DateTime'>{1}</Value></Eq><Eq><FieldRef Name='Nazwisko' /><Value Type='Text'>{2}</Value></Eq></And></Where>"; it count me one element which show "dataPoc" value.

share|improve this question
2  
This has been asked and answered here: sharepoint.stackexchange.com/questions/15770/… –  Justin Stenning Nov 15 '12 at 23:11
    
I write as You told, but it doesn't work. Please look my answer –  Grzegorz Z Nov 16 '12 at 9:58

1 Answer 1

Gt - greater operator

Lt - less operator

Look at this link for more information.

Code sample for you, you can use Geq - greater of equal and Leq - less or equal instead, depending of your case.

<And>
    <Gt><FieldRef Name='{0}' /><Value Type='DateTime'>{1}</Value></Gt>
    <Lt><FieldRef Name='{0}' /><Value Type='DateTime'>{1}</Value></Lt>
</And>
share|improve this answer
    
Use CAML Query Builder to make queries. It is for 2003 and 2007 SharePoint, but also works fine with SharePoint 2010 u2u.be/res/tools/camlquerybuilder.aspx –  Anton Khritonenkov Nov 16 '12 at 12:08
    
I'm using this, but that is need a parameters to send start, and end days. –  Grzegorz Z Nov 17 '12 at 15:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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