Need to have ShortDateTime Format with Datetime Type in DataGrid

G

Guest

I can't believe I have never run into this before but, I have an object that
has a property of type DateTime. A collection of these objects are used to
populate my DataGrid. In DateTime format they display the date AND the time,
I don't need nor want the time just the date. If I format at any point to a
ShortDate I have to convert the type to a string which when applied to the
grid interferes with sorting.
Is there any way to keep the datatype as DateTime but display only Date?
 
N

Nathan C.

I believe the DateTime class has a "Date" property which returns a DateTime
object with the time stripped I believe

Also, the ToString() method on DateTime has an override where you can pass a
format string, so you can do:

DateTime dtNow = DateTime.Now;
MessageBox.Show(dtNow.ToString("MM/dd/yyyy"));
 
G

Guest

Neither works, but thanks.

Nathan C. said:
I believe the DateTime class has a "Date" property which returns a DateTime
object with the time stripped I believe

Also, the ToString() method on DateTime has an override where you can pass a
format string, so you can do:

DateTime dtNow = DateTime.Now;
MessageBox.Show(dtNow.ToString("MM/dd/yyyy"));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top