How can I use VB DateDiff function in C#?

  • Thread starter Thread starter Derrick
  • Start date Start date
D

Derrick

I've included

using Microsoft.VisualBasic, cranked up a VBCodeProvider, the only class I
see in there, don't see DateDiff as a method though?

Thanks in advance!!

Derrick
 
Derrick,

You can add a reference to Microsoft.VisualBasic.dll, and then call the
static DateDiff function on the DateAndTime class which can be found in the
Microsoft.VisualBasic namespace.

Hope this helps.
 
using Microsoft.VisualBasic, cranked up a VBCodeProvider, the only class I
see in there, don't see DateDiff as a method though?

Thanks in advance!!

Another way;

TimeSpan diff = date1.Subtract (date2);
diff.TotalSeconds
diff.TotalMinutes
....

where "date1" and "date2" are DateTime variables, and diff - TimeSpan -
difference betweem two dates...
 
Back
Top