-1

I got a wrong date format to a CAML. I have got (yyyy-mm-dd) and must to be understand by CAML to the format(dd-mm-yyyy), how can I do this. I tried by String.Format("{0:yyyy-mm-dd}", dateISO1);, but it doesn't help. Here is my code:

  private void WyswietlanieUrlopow(SPWeb witryna1, DayRenderEventArgs e)
    {
        // Obszar odpowiedzialny za wyświetlenie i wypisanie dni urlopowych, jak też dni chorobowych pracowników


        //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 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><And><Eq><FieldRef Name='Nazwisko' /><Value Type='Note'>{4}</Value></Eq><Eq><FieldRef Name='Imie' /><Value Type='Note'>{5}</Value></Eq></And></And></And></Where>";
        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='LoginName' /><Value Type='Text'>{4}</Value></Eq></And></And></Where>";
        string dateISO1 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().AddHours(1.0));
        Convert.ToDateTime(dateISO1);
        string dateISO1con = String.Format("{0:yyyy-mm-dd}", dateISO1);
        string dateISO2 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().AddHours(2.0));
        Convert.ToDateTime(dateISO2);
        string dateISO2con = String.Format("{0:dd-mm-yyyy}", dateISO2);

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

        var queryPoszczegolnyUrlop = new SPQuery();
        queryPoszczegolnyUrlop.Query = String.Format(FullQueryUrlap, "DataKon", dateISO1con, "DataPoc", dateISO2con, DropDownList1.SelectedItem.Text);
        queryPoszczegolnyUrlop.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='DataPoc' /><FieldRef Name='DataKon' />";
        queryPoszczegolnyUrlop.ViewFieldsOnly = true;
1

You got wrong date format to a CAML. The date format (yyyy-mm-dd) and must to be understand by CAML to the format(dd-mm-yyyy). You can do this by String.Format("{0:yyyy-mm-dd}", dateISO1);, but it doesn't help. Here is my code: private void WyswietlanieUrlopow(SPWeb witryna1, DayRenderEventArgs e) { // Obszar odpowiedzialny za wyświetlenie i wypisanie dni urlopowych, jak też dni chorobowych pracowników

    //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 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><And><Eq><FieldRef Name='Nazwisko' /><Value Type='Note'>{4}</Value></Eq><Eq><FieldRef Name='Imie' /><Value Type='Note'>{5}</Value></Eq></And></And></And></Where>";
    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='LoginName' /><Value Type='Text'>{4}</Value></Eq></And></And></Where>";
    string dateISO1 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().AddHours(1.0));
    Convert.ToDateTime(dateISO1);
    string dateISO1con = String.Format("{0:yyyy-mm-dd}", dateISO1);
    string dateISO2 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().AddHours(2.0));
    Convert.ToDateTime(dateISO2);
    string dateISO2con = String.Format("{0:dd-mm-yyyy}", dateISO2);

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

    var queryPoszczegolnyUrlop = new SPQuery();
    queryPoszczegolnyUrlop.Query = String.Format(FullQueryUrlap, "DataKon", dateISO1con, "DataPoc", dateISO2con, DropDownList1.SelectedItem.Text);
    queryPoszczegolnyUrlop.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='DataPoc' /><FieldRef Name='DataKon' />";
    queryPoszczegolnyUrlop.ViewFieldsOnly = true;
  • 1
    This helped me resolve the issue – Kumar Reddy Nov 15 '16 at 17:07
0

Have a look at this:
Query list with CAML - DateTime column

Use this:
SPUtility.CreateISO8601DateTimeFromSystemDateTime(dateISO2)

I hope this helps

  • But Arsalan i Used this : string dateISO2 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().AddHours(2.0)); Please look at code :) – Grzegorz Z Dec 14 '12 at 15:29
  • 1
    What is the problem in above ?? – Arsalan Adam Khatri Dec 14 '12 at 20:27
  • I getting the date from External List yyyy-mm-dd, and I want to get in format dd-mm-yyyy, because only in this format date is understood my dates. – Grzegorz Z Dec 15 '12 at 20:56

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.