Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Small method to calculate since time
Message
From
08/10/2011 11:53:58
 
 
To
08/10/2011 06:51:45
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01525501
Message ID:
01525892
Views:
42
OK. Classic bodge:
static DateTimeSpan GetDateDiff(DateTime startDate, DateTime endDate)
        {
            int year = endDate.Year;
            int month = endDate.Month;

            TimeSpan startSpan = new TimeSpan(startDate.Day, startDate.Hour, startDate.Minute, startDate.Second);
            TimeSpan endSpan = new TimeSpan(endDate.Day, endDate.Hour, endDate.Minute, endDate.Second);

            if (endSpan - startSpan < new TimeSpan(0))
            {
                month -= 1;
                if (month == 0)
                {
                    month = 12;
                    year -= 1;
                }
            }
            TimeSpan ts =
                endDate.Subtract(new DateTime(year, month, startDate.Day, startDate.Hour, startDate.Minute, startDate.Second));
            DateTimeSpan dts =
                new DateTimeSpan(year - startDate.Year, month - startDate.Month, ts.Days, ts.Hours, ts.Minutes, ts.Seconds);

            if (dts.Months < 0)
            {
                dts.Months = 12 + dts.Months;
                dts.Years = dts.Years - 1;
            }
            return dts;
        }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform