-2

I'm having trouble converting VB.Net to C#.Net. There is DateDiff() function in the code, and I'm having trouble to find the equivalent function in C#. My code in VB is below:

'If the differnce between Now and the files header date >1 (day,week or year) then
If DateDiff(sDateInterval, dFileDate, Now) >= 1 Then
    Return True 'File over write is necessary 
Else
    Return False 'File over write is not necessary 
End If
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
rei123
  • 63
  • 1
  • 1
  • 11

1 Answers1

3

DateDiff doesn't exist in C#, you simply subtract two dates:

DateTime date1 = somevalue;
DateTime date2 = someothervalue;

TimeSpan difference = date2 - date1;

So you can then retrieve, for example, difference.TotalSeconds.

See the MSDN page for more information.

If you want to maintain the same interval functionality, there's nothing to stop you referencing Microsoft.VisualBasic and using the method you already do: DateAndTime.DateDiff MSDN page

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86