Geekpedia Forums Logo

Work with Date

by Sasha Desperate on Wednesday, January 14th - 3:51 AM



how calculate date2 - date1 in months and days?
Как посчитать разность между датами в месяцах и днях
string dt = 10,24 (10 месяцев и 24 дня) 


                int year = System.DateTime.Today.Year;
                int month = System.DateTime.Today.Month;
                int date = System.DateTime.Today.Day;
                string today = date.ToString() + "/" + month.ToString() + "/" + year.ToString();
                int len = today.Length;
               
                             
                    int ydate = date - 1;
                    if (ydate <= 0)
                    {
                        month--;
                        if (month <= 0)
                        {
                            year--;
                            month = 12;
                        }
                        ydate = System.DateTime.DaysInMonth(year, month);
                       
                    }
                    string yday = ydate.ToString() + "/" + month.ToString() + "/" + year.ToString();





This is the code in which you can perform any task on dates.....
please understood and try it your self...