For example:
2011-08-11 16:59 becomes 2011-08-11 16:30
DateTime RoundDown(DateTime dt, TimeSpan d)
{
return new DateTime((dt.Ticks / d.Ticks) * d.Ticks);
}
Example:
var dt1 = RoundDown(DateTime.Parse("2011-08-11 16:59"), TimeSpan.FromMinutes(30));
// dt1 == {11/08/2011 16:30:00}
var dt2 = RoundDown(DateTime.Parse("2011-08-11 17:00"), TimeSpan.FromMinutes(30));
// dt2 == {11/08/2011 17:00:00}
var dt3 = RoundDown(DateTime.Parse("2011-08-11 17:01"), TimeSpan.FromMinutes(30));
// dt3 == {11/08/2011 17:00:00}
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