snippetcsharpCritical
How to remove time portion of date in C# in DateTime object only?
Viewed 0 times
objecthowdatetimedatetimeremoveportiononly
Problem
I need to remove time portion of date time or probably have the date in following format in
I can not use any
I tried first converting the
object form not in the form of string.06/26/2009 00:00:00:000I can not use any
string conversion methods as I need the date in object form.I tried first converting the
DateTime to a string, remove the time specific date from it, but it adds 12:00:00 AM as soon as I convert it back to DateTime object back again.Solution
Use the Date property:
The
var dateAndTime = DateTime.Now;
var date = dateAndTime.Date;The
date variable will contain the date, the time part will be 00:00:00.Code Snippets
var dateAndTime = DateTime.Now;
var date = dateAndTime.Date;Context
Stack Overflow Q#6121271, score: 1076
Revisions (0)
No revisions yet.