Mayank Jani

Mayank Jani

  • NA
  • 477
  • 76.5k

How to separate time from db datetime?

Mar 29 2018 12:00 PM
Hi members,
 
Greetings of the day...
 
a time field in my Access db table, log in time is recorded as '10:30 AM' but when I fetch the record to a DGV, it shows as '30/12/1899 10:30 AM' !!!
 
I am surprising why the date is showing of the year 1899. the data type is date/time and format is Medium Date' the time data also being saved as mentioned above but the out put in DGV shows with date. I want it to be displayed as it is in the db.
 
I have found some functions that separates/extracts time from the date but the display remains the same.
 
DateTime dt = DateTime.Now;
string CONVdt = dsFetchAppo.Tables[0].Rows[0].ItemArray[3].ToString();

DateTime.TryParse(CONVdt, out dt);

string CONVtime = dt.ToString("H:mm tt"); 
 
 
please note that it's C# WinApp and database is MS Access.
 
Thank You
 
Mayank Jani

Answers (14)