By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,710 Members | 1,613 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,710 IT Pros & Developers. It's quick & easy.

Need to have ShortDateTime Format with Datetime Type in DataGrid

P: n/a
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?
Oct 7 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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"));

"A Programmer" <AP*********@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
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?

Oct 7 '05 #2

P: n/a
Neither works, but thanks.

"Nathan C." wrote:
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"));

"A Programmer" <AP*********@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
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?


Oct 7 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.