0
cmd.Parameters.Add("@Date", dtp_Date.Value);

This code is inserted date in "M/dd/yyyy" format but I want to insert date in dd-MM-yyyy format in ms access database.

Elixir
  • 287
  • 2
  • 3
  • 14

4 Answers4

0

You can store DateTime in any format in Database.

You require to convert when you want to show it on screem(e.g. View)

For that case use DateTime.TryParseExact:

 DateTime dtReturn;

DateTime.TryParseExact(dtp_Date.Value, 'dd-MM-yyyy', CultureInfo.InvarientCulture, DateTimeStyles.None, out dtReturn);
Neel
  • 11,625
  • 3
  • 43
  • 61
0

I'm assuming your database field type is 'datetime' and dtp_date is ''String. If so, use the below line of code,

DateTime date = DateTime.ParseExact(dtp_Date, "dd-MM-yyyy", null);
gkrishy
  • 756
  • 1
  • 8
  • 33
0

By assuming that you are inserting into a mysql database, it supports only yyyy-mm-dd format for date. you can format the date while retrieving it from the DB. Link for mysql date functions

0

Datetime in ms access is not stored with it's display format. In fact, it's stored as a double:

Access stores the Date/Time data type as a double-precision, floating-point number up to 15 decimal places. The integer part of the double-precision number represents the date. The decimal portion represents the time.

You should deal with display format when selecting from the table.

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121