I need to remove time portion of date time or probably have the date in following format in object form not in the form of string.
06/26/2014 00:00:00:000
I can not use any string conversion methods as I need the date in object form.
I tried first converting the date to string, remove the time specific date from it, but it adds 12:00:00 AM as soon as I convert it to DateTime object back again.
You can't create a DateTime object without a time in it. It always has some time in it.
If you want to output it without a time portion, you can use a format string to do so:
date.ToString("MM/dd/yyyy");
Standard Date and Time Format Strings
Custom Date and Time Format Strings
As others have said, you can access date.Date
to get a value with any specific time information omitted, but that will still have a time of 00:00 AM.
You can use the Date property of DateTime object to get only day.
DateTime dateOnly = date1.Date;
If you want string of Date from the DateTime object then use the ToString method by providing it the format. You can read more about custom date format in this MSDN article.
string strDate = date.ToString("MM/dd/yyyy");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With