0

Im using monthCalendar for mssql queries. I have problem on clients OS date format. I have datetype column but for example this query

asdf = new SqlDataAdapter("SELECT Firma, Czas, Opis,ID FROM Rok2016 WHERE Dzien=@DT AND Kto=@Kto", con);
        asdf.SelectCommand.Parameters.AddWithValue("@DT", monthCalendar1.SelectionRange.Start.ToShortDateString());
        asdf.SelectCommand.Parameters.AddWithValue("@Kto", label3.Text);

adds YYYY-MM-DD on OS where this dateformat is using but on diffrent its YYYY-DD-MM. How to set monthCalendar1.SelectionRange.Start.ToShortDateString() with one specific format YYYY-MM-DD for all OS? I tried to set one culture info for thread but it still doesnt work.

Thanks

1 Answers1

0

Try something like

    String whatever = monthCalendar1.SelectedDate.Start.ToString("YYYY-MM-DD hh:mm:ss");

Edit: SQL does not understand YYYY-MM-DD, try above instead.

LSA
  • 404
  • 7
  • 11
  • Conversion failed when converting date and/or time from character string. – Krystian Mołas Apr 08 '17 at 13:29
  • tried monthCalendar1.SelectionRange.Start.ToString("YYYY-MM-DD hh:mm:ss")); the same error – Krystian Mołas Apr 08 '17 at 13:41
  • tried monthCalendar1.SelectedDate.Start.ToString("YYYY-MM-DD hh:mm:ss"); error Severity Code Description Project File Line Suppression State Error CS1061 'MonthCalendar' does not contain a definition for 'SelectedDate' and no extension method 'SelectedDate' accepting a first argument of type 'MonthCalendar' could be found (are you missing a using directive or an assembly reference?) – Krystian Mołas Apr 08 '17 at 13:41
  • Have a look here [link](https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql) – LSA Apr 08 '17 at 13:42
  • of which type is your monthCalendar1? – LSA Apr 08 '17 at 13:46
  • Sorry what do you mean by which type? Where can I check it? – Krystian Mołas Apr 08 '17 at 13:48
  • I guess it is a MonthCalendar? Get the year, month and day, then you could do something like `System.DateTime(year, month, day, 0, 0, 0, 0).toString("YYYY-MM-DD hh:mm:ss")` – LSA Apr 08 '17 at 13:55
  • http://stackoverflow.com/questions/16748224/show-a-particular-row-from-sql-server-connected-to-month-calendar-specific-date This was helpfull – Krystian Mołas Apr 08 '17 at 14:34