sqlvb.netms-accessms-access-2007datetimepicker

.NET DataGridView displays 1899-12-30 as part of a time-only value


I set my datetimepicker's value to 1:00 PM or any random hh:mm tt format and insert it into my MSAccess database in a my table with a date/time field. But when my datagridview shows the table, a random "12/30/1899" (+ my input of 1:00 PM). Any idea why this is happening? My code is not here though.


Solution

  • Access Date/Time fields always store both a Date and a Time component. If only a Time value is specified then the Date part defaults to 1899-12-30.

    If you want to display just the Time part in a DataGridView column you can set its format to "short time" using something like this (C#, but VB.NET would be very similar):

    dataGridView1.Columns[3].DefaultCellStyle.Format = "t";  // short time