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

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;
share|improve this question
    
I like using [Moment.js][1] instead of messing with SPUtility. [1]: stackoverflow.com/questions/17093796/… –  James Grizzle Nov 18 at 19:56

1 Answer 1

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

Use this:
SPUtility.CreateISO8601DateTimeFromSystemDateTime(dateISO2)

I hope this helps

share|improve this answer
    
But Arsalan i Used this : string dateISO2 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().A‌​ddHours(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

 
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.