Reputation: 29
I have a DateTimePicker in C# and in the database I have a datetime column.
I've set dd/MM/yyyy as properties of the DateTimePicker but it saves mm/dd/yyyy in the database with the time at 00:00:00.000.
I want to coordinate this DateTimePicker with the column data and I don't want to show the time in the database.
How do I do that?
Upvotes: 3
Views: 6251
Reputation: 8444
SQL Server has a date
type, therefore even if the time portion is sent to SQL Server, SQL Server will only store the date portion. For example:
// CREATE TABLE DateStorage
// (
// Dates date
// )
DateTime now = DateTime.Now;
// now.ToString() -> 2013-05-24 09:39:00.0000000+00:00
// ---- INSERT ------
Db.Insert("DateStorage", now);
// Dates
// --------------
// 2013-05-24
// ----- READ -----
DateTime date = Db.Read("DateStorage").Rows[0]["Dates"] as DateTime;
// date.ToString() => 2013-05-24 00:00:00.00000 +00:00
Upvotes: 2