Public Enum dateinterval
{
Second, minute, hour, day, week, month, quarter, year
}
Public long datediff (dateinterval interval, system. datetime startdate, system. datetime enddate)
...{
Long lngdatediffvalue = 0;
System. timespan Ts = new system. timespan (enddate. ticks-startdate. ticks );
Switch (interval)
...{
Case dateinterval. Second:
Lngdatediffvalue = (long) Ts. totalseconds;
Break;
Case dateinterval. minute:
Lngdatediffvalue = (long) Ts. totalminutes;
Break;
Case dateinterval. hour:
Lngdatediffvalue = (long) Ts. totalhours;
Break;
Case dateinterval. Day:
Lngdatediffvalue = (long) Ts. days;
Break;
Case dateinterval. Week:
Lngdatediffvalue = (long) (TS. Days/7 );
Break;
Case dateinterval. month:
Lngdatediffvalue = (long) (TS. Days/30 );
Break;
Case dateinterval. quarter:
Lngdatediffvalue = (long) (TS. Days/30)/3 );
Break;
Case dateinterval. Year:
Lngdatediffvalue = (long) (TS. Days/365 );
Break;
}
Return (lngdatediffvalue );
}