1

I created a format with a date. It's XML code is very easy:

<DatePicker x:Name="data" Grid.Row="4" TextColor="Silver" MinimumDate="12/12/1900"/>

But I need to save this date in SQL, but the format is wrong. The format of SQL is yyy-mm-gg while the format of datepicker is mm-gg-yyyy.

How can i change this? thanks a lot

Alessia
  • 59
  • 7

1 Answers1

2

A date is always a date regardless of how you format it in the UI.

You should store the value as a DATE in the database and retrieve it from the DatePicker using the Date property. It returns a DateTime that you should insert into the database using a parameter.

Please read the following regarding how and why to use parameters in your SQL statements:

How can I add user-supplied input to an SQL statement?

You may format a DateTime programmatically using the ToString method overload that accepts a format string:

data.Date.ToString("yyyy-MM-dd")
mm8
  • 163,881
  • 10
  • 57
  • 88