public static string CalculateAge(string date)
        {
            DateTime dateOfBirth = Convert.ToDateTime(DateTimeNow());
            int      ageInYears  = 0;
            int      ageInMonths = 0;
            int      ageInDays   = 0;

            if (ValedationClass.IsValiDateTime(date, ConstansValuesClass.formatDate) == true)
            {
                dateOfBirth = Convert.ToDateTime(date);
                DateTime currentDate = Convert.ToDateTime(DateTimeNow());
                TimeSpan difference  = currentDate.Subtract(dateOfBirth);

                // This is to convert the timespan to datetime object
                DateTime age = DateTime.MinValue + difference;

                // Min value is 01/01/0001
                // Actual age is say 24 yrs, 9 months and 3 days represented as timespan
                // Min Valye + actual age = 25 yrs , 10 months and 4 days.
                // subtract our addition or 1 on all components to get the actual date.

                ageInYears  = age.Year - 1;
                ageInMonths = age.Month - 1;
                ageInDays   = age.Day - 1;
            }
            return(ConvertNumberToArFormat(ageInYears + " سنوات ," + ageInMonths + " شهر , " + ageInDays + " أيام"));
        }
 public static bool ConvertToBool(object value)
 {
     if (value == null)
     {
         value = "";
     }
     return(ValedationClass.IsValidBollenValue(value.ToString()) == false ? false : Convert.ToBoolean(value));
 }
 public static double ConvertToDouble(object value)
 {
     if (value == null)
     {
         value = "";
     }
     return(ValedationClass.IsValidNumber(value.ToString()) == false ? 0 : Convert.ToDouble(value));
 }
 public static string ConvertToString(object value)
 {
     if (value == null)
     {
         value = "";
     }
     return(ValedationClass.IsValidEmpty(value.ToString()) == true ? "" : value.ToString());
 }
        public static TimeSpan GetTimeDiffernceTimespan(string s1, string s2)
        {
            DateTime dt2 = ValedationClass.IsValidEmpty(s2) == true?Convert.ToDateTime(DateTimeNow()) : Convert.ToDateTime(s2);

            DateTime dt1 = ValedationClass.IsValidEmpty(s1) == true?Convert.ToDateTime(DateTimeNow()) : Convert.ToDateTime(s1);

            TimeSpan ts = dt2.Subtract(dt1);

            return(ts);
        }
        public static string GetTimeDiffernce(string s1, string s2)
        {
            DateTime dt2 = ValedationClass.IsValidEmpty(s2) == true?Convert.ToDateTime(DateTimeNow()) : Convert.ToDateTime(s2);

            DateTime dt1 = ValedationClass.IsValidEmpty(s1) == true?Convert.ToDateTime(DateTimeNow()) : Convert.ToDateTime(s1);

            TimeSpan ts     = dt2.Subtract(dt1);
            string   result = ChangeFormatTimeSpan(ts, ConstansValuesClass.timeSpanFormat);

            return(result);
        }
 public static string ConvertToDate(object value)
 {
     try
     {
         return(ValedationClass.IsValidEmpty(value.ToString()) == true ? "" : Convert.ToDateTime(value).ToString(ConstansValuesClass.formatDate));
     }
     catch
     {
         return("");
     }
 }
        public static string ConvertToTime(object value)
        {
            try
            {
                //return ValedationClass.IsValidEmpty(value.ToString()) == true ? "" : DateTime.ParseExact(value.ToString(), ConstansValuesClass.formatTime,
                //                        CultureInfo.InvariantCulture).ToString();

                return(ValedationClass.IsValidEmpty(value.ToString()) == true ? "" : DateTime.Parse(value.ToString()).ToString(ConstansValuesClass.formatTime));
            }
            catch
            {
                return("");
            }
        }
        public static string GetNameDayArabic(string dt)
        {
            string dayName = "";

            try
            {
                if (ValedationClass.IsValidEmpty(MethodesConvertalClass.ConvertToDate(dt)) == false)
                {
                    DateTime dateTime = Convert.ToDateTime(MethodesConvertalClass.ConvertToDate(dt));
                    var      culture  = new CultureInfo("ar-Eg");
                    dayName = culture.DateTimeFormat.GetDayName(dateTime.DayOfWeek).Trim();
                    return(dayName);
                }
            }
            catch
            {
            }
            return(dayName);
        }
        public static string CalculateRemainedTime(string dateTime, string language)
        {
            string time = "Un Known";

            DateTime date_time_reminder = ValedationClass.IsValidEmpty(dateTime) == true?Convert.ToDateTime(DateTimeNow()) : Convert.ToDateTime(dateTime);

            DateTime date_time_now = Convert.ToDateTime(DateTimeNow());

            if (date_time_now < date_time_reminder)
            {
                TimeSpan time_span = date_time_reminder - date_time_now;
                time = string.Format("{0:00}:{1:00}:{2:00}", time_span.Hours, time_span.Minutes, time_span.Seconds);
                if (language == ConstansValuesClass.languageCodeEn)
                {
                    return("Left: " + time_span.Days.ToString() + " days, " + time);
                }
                else
                {
                    return("بعد: " + time_span.Days.ToString() + " ايام, " + time);
                }
            }
            else if (date_time_now >= date_time_reminder)
            {
                TimeSpan time_span = date_time_now - date_time_reminder;
                time = string.Format("{0:00}:{1:00}:{2:00}", time_span.Hours, time_span.Minutes, time_span.Seconds);
                if (language == ConstansValuesClass.languageCodeEn)
                {
                    return("Ago: " + time_span.Days.ToString() + " ايام, " + time);
                }
                else
                {
                    return("منذ: " + time_span.Days.ToString() + " ايام, " + time);
                }
            }
            return(time);
        }