You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/Extensions/DateTimeExtensions.cs

18 lines
576 B

6 years ago
using System;
namespace ZeroLevel
{
public static class DateTimeExtensions
{
/// <summary>
/// Rounds the date to the specified scale.
/// Example: sqlserver - Datetime values are rounded to increments of .000, .003, or .007 seconds
6 years ago
/// </summary>
public static DateTime Truncate(this DateTime dateTime, TimeSpan timeSpan)
{
if (timeSpan == TimeSpan.Zero) return dateTime; // Or could throw an ArgumentException
return dateTime.AddTicks(-(dateTime.Ticks % timeSpan.Ticks));
}
}
}

Powered by TurnKey Linux.