Take the 2-minute tour ×

I am working on a database driven c# application.

I have a datatable that has a date column in it. Bind this datatable to datagridview and let the user edit the records and upon clicking save, save these changes in the database.

Date format in grid changes based on the system settings between dd/MM/yyyy and MM/dd/yyyy.

Data entry operators are not smart enough to look at this difference, so while editing the records they sometime move the records to different month.

Date Format is dd/MM/yyyy 10/10/2010

They want to change it to 12th October from 10th October. They made this change 10/12/2010 assuming the date format is MM/dd/yyyy.

There always remains this problem, so I want to fix the date format in the datatable.

What are the approaches I could use?

share|improve this question
Formatting of dates is a UI issue, not a persistence issue. If dates are stored in a DATETIME column, that's about it for the database. Fix the UI. –  Oded Dec 15 '12 at 14:34
in the Column properties DefaultCellStyle you could set the Format to MM/dd/yyyy –  spajce Dec 15 '12 at 14:57
add comment

2 Answers

up vote 0 down vote accepted

Use this code

var style = new DataGridViewCellStyle();
style.Format = "dd-MMM-yy";
colDate.DefaultCellStyle = style;

You don't need to convert it back and forth, it'll do all the things you want to achieve,

share|improve this answer
add comment

Are you setting the Column DataType as DateTime? I don't understand why this issue can occur. Internally, .NET should be saving this cell value as DateTime, and passing this to the database. Date formatting is not an issue.

share|improve this answer
add comment

Your Answer


