Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save Date Time without the time?

Tags:

c#

datetime

How would i save the date time, with no time or preferably with a time stamp of 12:00, no matter what the time is at that moment?

I dont want to use .ToString("dd/MM/yyyy");, because it will open up a whole lot of new possible errors.

like image 857
Willem Avatar asked Nov 30 '10 11:11

Willem


People also ask

How can store date without time in SQL?

Use Date Data type to create a Date column/variable without any time information. The time defaults to 00:00:00 and sql server will not store it in the Database. Hence it is very efficient way to store date, when there is no need to store time.

What is the format of DateTime?

For example, the "d" standard format string indicates that a date and time value is to be displayed using a short date pattern. For the invariant culture, this pattern is "MM/dd/yyyy". For the fr-FR culture, it is "dd/MM/yyyy". For the ja-JP culture, it is "yyyy/MM/dd".


1 Answers

DateTime struct has a Date property that should serve your needs:

DateTime dateOnly = dateTime.Date;

Of course, it'll still inevitably contain a time part but you should be able to ignore it.

like image 187
mmx Avatar answered Oct 07 '22 02:10

mmx