What’s the best way to trim a DateTime object to a specific precision? For instance, if I have a DateTime with a value of ‘2008-09-29 09:41:43’, but I only want it’s precision to be to the minute, is there any better way to do it than this?
private static DateTime TrimDateToMinute(DateTime date) { return new DateTime( date.Year, date.Month, date.Day, date.Hour, date.Minute, 0); }
What I would really want is to make it variable so that I could set its precision to the second, minute, hour, or day.
1 Answer