public static long Diff(DatePartType datePart, DateTime dt1, DateTime dt2) { switch (datePart) { case DatePartType.Year: return dt2.Year - dt1.Year; case DatePartType.Quarter: return (dt2.Year - dt1.Year) * 4 + (dt2.Month - 1) / 3 - (dt1.Month - 1) / 3; case DatePartType.Month: return (dt2.Year - dt1.Year) * 12 + dt2.Month - dt1.Month; case DatePartType.Day: case DatePartType.DayOfYear: case DatePartType.DayOfWeek: return (dt2.Date - dt1.Date).Days; case DatePartType.Hour: return dt2.Ticks / TimeSpan.TicksPerHour - dt1.Ticks / TimeSpan.TicksPerHour; case DatePartType.Minute: return dt2.Ticks / TimeSpan.TicksPerMinute - dt1.Ticks / TimeSpan.TicksPerMinute; case DatePartType.Second: return dt2.Ticks / TimeSpan.TicksPerSecond - dt1.Ticks / TimeSpan.TicksPerSecond; case DatePartType.MilliSecond: return dt2.Ticks / TimeSpan.TicksPerMillisecond - dt1.Ticks / TimeSpan.TicksPerMillisecond; case DatePartType.MicroSecond: return dt2.Ticks / TimeSpan.TicksPerMillisecond / 1000 - dt1.Ticks / TimeSpan.TicksPerMillisecond / 1000; case DatePartType.NanoSecond: return dt2.Ticks / TimeSpan.TicksPerMillisecond / 1000000 - dt1.Ticks / TimeSpan.TicksPerMillisecond / 1000000; default: throw new InvalidOperationException (string.Format ("Unknown DatePart type '{0}'", datePart)); } }
public static DateTime Add(DatePartType datePart, long add, DateTime dt) { switch (datePart) { case DatePartType.Year: return dt.AddYears ((int)add); case DatePartType.Quarter: return dt.AddMonths ((int)add * 3); case DatePartType.Month: return dt.AddMonths ((int)add); case DatePartType.Day: case DatePartType.DayOfYear: case DatePartType.DayOfWeek: return dt.AddDays (add); case DatePartType.Hour: return dt.AddHours (add); case DatePartType.Minute: return dt.AddMinutes (add); case DatePartType.Second: return dt.AddSeconds (add); case DatePartType.MilliSecond: return dt.AddMilliseconds (add); case DatePartType.MicroSecond: return dt.AddTicks (add * TimeSpan.TicksPerMillisecond / 1000); case DatePartType.NanoSecond: return dt.AddTicks (add * TimeSpan.TicksPerMillisecond / 1000000); default: throw new InvalidOperationException (string.Format ("Unknown DatePart type '{0}'", datePart)); } }
public static string DatePart(string columnName, DatePartType partType) { StringBuilder sb = new StringBuilder("DATEPART("); sb.Append(partType.ToString()); sb.Append(','); SqlQueryUtils.AppendColumnName(sb, columnName); sb.Append(')'); return(sb.ToString()); }
public static string DatePart(string columnName, DatePartType partType) { Check.Require(!string.IsNullOrEmpty(columnName), "columnName could not be null or empty!"); StringBuilder sb = new StringBuilder("DATEPART("); sb.Append(partType.ToString()); sb.Append(','); SqlQueryUtils.AppendColumnName(sb, columnName); sb.Append(')'); return sb.ToString(); }
public static Function DateAdd(DatePartType datePart, Expression number, Expression date) { if (number == null) { throw new ArgumentNullException("number"); } if (date == null) { throw new ArgumentNullException("date"); } return new DateAddFunction(datePart, number, date); }
public static string DatePart(string columnName, DatePartType partType) { Check.Require(!string.IsNullOrEmpty(columnName), "columnName could not be null or empty!"); StringBuilder sb = new StringBuilder("DATEPART("); sb.Append(partType.ToString()); sb.Append(','); SqlQueryUtils.AppendColumnName(sb, columnName); sb.Append(')'); return(sb.ToString()); }
public static Function DateAdd(DatePartType datePart, Expression number, Expression date) { if (number == null) { throw new ArgumentNullException("number"); } if (date == null) { throw new ArgumentNullException("date"); } return(new DateAddFunction(datePart, number, date)); }
public DateAddFunctionView(DatePartType type) { Type = type; }
public DatePartFunction DatePart(DatePartType partType) { return(new DatePartFunction(partType, this)); }
public static long Get(DatePartType datePart, DateTime dt) { switch (datePart) { case DatePartType.Year: return dt.Year; case DatePartType.Quarter: return (dt.Month - 1) / 3 + 1; case DatePartType.Month: return dt.Month; case DatePartType.DayOfYear: return dt.DayOfYear; case DatePartType.Day: return dt.Day; case DatePartType.DayOfWeek: return (int)dt.DayOfWeek + 1; case DatePartType.Hour: return dt.Hour; case DatePartType.Minute: return dt.Minute; case DatePartType.Second: return dt.Second; case DatePartType.MilliSecond: return dt.Millisecond; case DatePartType.MicroSecond: return (dt.Ticks % TimeSpan.TicksPerSecond) / (TimeSpan.TicksPerMillisecond / 1000); case DatePartType.NanoSecond: return (dt.Ticks % TimeSpan.TicksPerSecond) * 1000 / (TimeSpan.TicksPerMillisecond / 1000); default: throw new InvalidOperationException (string.Format ("Unknown DatePart type '{0}'", datePart)); } }
public DatePartFunction(DatePartType partType, IQueryValueExpression expression) : base(expression) { PartType = partType; }
public DateAddFunction(DatePartType datePart, Expression number, Expression date) { this.DatePart = datePart; this.Number = number; this.Date = date; }