/// <summary> /// Return 2 Dates difference /// </summary> /// <param name="date1">First Date (DateTime Format)</param> /// <param name="date2">Second Date (DateTime Format)</param> /// <returns>Double , difference between two dates</returns> public static double Get_Dates_Different(DateTime date1, DateTime date2, Date_Diff_Type diff_type) { try { // calculate difference between two dates TimeSpan diff = (date1 - date2); // then convert the difference in desire format if (diff_type == Date_Diff_Type.In_MilliSeonds) { return(diff.TotalMilliseconds); } if (diff_type == Date_Diff_Type.In_Seconds) { return(diff.TotalSeconds); } if (diff_type == Date_Diff_Type.In_Minutes) { return(diff.TotalMinutes); } if (diff_type == Date_Diff_Type.In_Hours) { return(diff.TotalHours); } if (diff_type == Date_Diff_Type.In_Days) { return(diff.TotalDays); } } catch { return(-1); } return(-1); }
/// <summary> /// Return 2 Persian Dates difference /// </summary> /// <param name="date1">First Date (String Format)</param> /// <param name="date2">Second Date (String Format)</param> /// <returns>Double , difference between two dates</returns> public static double Get_Persian_Dates_Difference(String date1, String date2, Date_Diff_Type diff_type) { try { if (validate_Persian_Date_format(date1) == false || validate_Persian_Date_format(date2) == false) { throw new DateTime_Exceptions.NotValidPersianDate(); } // calculate difference between two dates DateTime dt_1 = Persian_To_Greagorian(date1); DateTime dt_2 = Persian_To_Greagorian(date2); TimeSpan diff = (dt_1 - dt_2); // then convert the difference in desire format if (diff_type == Date_Diff_Type.In_MilliSeonds) { return(diff.TotalMilliseconds); } if (diff_type == Date_Diff_Type.In_Seconds) { return(diff.TotalSeconds); } if (diff_type == Date_Diff_Type.In_Minutes) { return(diff.TotalMinutes); } if (diff_type == Date_Diff_Type.In_Hours) { return(diff.TotalHours); } if (diff_type == Date_Diff_Type.In_Days) { return(diff.TotalDays); } } catch { return(-1); } return(-1); }