Beispiel #1
0
        public static void GetDuratioin(DateTimeConstants constants, ref string begin, ref string end)
        {
            switch (constants)
            {
            case DateTimeConstants.Today:
                begin = DateTime.Today.ToString("yyyyMMdd");
                end   = DateTime.Today.AddDays(1).ToString("yyyyMMdd");
                break;

            case DateTimeConstants.Yesterday:
                begin = DateTime.Today.AddDays(-1).ToString("yyyyMMdd");
                end   = DateTime.Today.ToString("yyyyMMdd");
                break;

            case DateTimeConstants.LastWeek:
                begin = DateTime.Today.AddDays(-7).ToString("yyyyMMdd");
                end   = DateTime.Today.ToString("yyyyMMdd");
                break;

            case DateTimeConstants.LastMonth:
                begin = DateTime.Today.AddMonths(-1).ToString("yyyyMMdd");
                end   = DateTime.Today.ToString("yyyyMMdd");
                break;

            case DateTimeConstants.ThisYear:
                begin = DateTime.Today.AddYears(-1).ToString("yyyyMMdd");
                end   = DateTime.Today.ToString("yyyyMMdd");
                break;

            case DateTimeConstants.LastYear:
                begin = DateTime.Today.AddYears(-2).ToString("yyyyMMdd");
                end   = DateTime.Today.ToString("yyyyMMdd");
                break;
            }
        }
Beispiel #2
0
        public static void GetDuratioin(DateTimeConstants constants, ref string begin, ref string end)
        {
            switch(constants)
             {
                 case DateTimeConstants.Today:
                     begin = DateTime.Today.ToString("yyyyMMdd");
                     end = DateTime.Today.AddDays(1).ToString("yyyyMMdd");
                     break;

                 case DateTimeConstants.Yesterday:
                     begin = DateTime.Today.AddDays(-1).ToString("yyyyMMdd");
                     end = DateTime.Today.ToString("yyyyMMdd");
                     break;

                 case DateTimeConstants.LastWeek:
                     begin = DateTime.Today.AddDays(-7).ToString("yyyyMMdd");
                     end = DateTime.Today.ToString("yyyyMMdd");
                     break;

                 case DateTimeConstants.LastMonth:
                     begin = DateTime.Today.AddMonths(-1).ToString("yyyyMMdd");
                     end = DateTime.Today.ToString("yyyyMMdd");
                     break;

                 case DateTimeConstants.ThisYear:
                     begin = DateTime.Today.AddYears(-1).ToString("yyyyMMdd");
                     end = DateTime.Today.ToString("yyyyMMdd");
                     break;

                 case DateTimeConstants.LastYear:
                     begin = DateTime.Today.AddYears(-2).ToString("yyyyMMdd");
                     end = DateTime.Today.ToString("yyyyMMdd");
                     break;
             }
        }
Beispiel #3
0
 private static void GetDuration(string duration, ref string begin, ref string end)
 {
     if (string.IsNullOrWhiteSpace(duration))
     {
         begin = string.Empty;
         end   = string.Empty;
     }
     else
     {
         DateTimeConstants constants = (DateTimeConstants)Enum.Parse(typeof(DateTimeConstants), duration);
         GetDuratioin(constants, ref begin, ref end);
     }
 }
Beispiel #4
0
 public static void ConvertTimeSpanToSql_SqlServer(this StringBuilder stringBuilder, SqlDataType sqlDataType, TimeSpan value)
 {
     if (sqlDataType.Type.DataType == DataType.Int64)
     {
         stringBuilder.Append(value.Ticks);
     }
     else
     {
         var format = value.Days > 0
   ? DateTimeConstants.TimeSpanFormat(value.Ticks % 10000000 != 0 ? 7 : 0)
   : DateTimeConstants.SqlTimeFormat(value.Ticks % 10000000 != 0 ? 7 : 0);
         stringBuilder.AppendFormat(CultureInfo.InvariantCulture, format, value);
     }
 }
Beispiel #5
0
 public static string ToSqlTime(this TimeSpan ts, int milliSecondsPrecision = 0) => ts.ToString(DateTimeConstants.SqlTimeFormat(milliSecondsPrecision));