How to do DateDiff() in C#.net?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, guys,

How to do DateDiff(), as you remember, a powerful and nice VB function, in
c#.net? I could not find this funciton.

Thanks a lot.
 
Hello,

you can just subtract two dates from one another and you'll get a TimeSpan
instance.

dim diff as TimeSpan

diff = DateTime.Now - DateTime.Today

Best regards,
Henning Krause
 
Henning,

Is that not something as,

in C#
TimeSpan GiveTheTimeOfTheDay = DateTime.Now - DateTime.Today;
In VB
GiveTheTimeOfTheDay as TimeSpan = Now - DateTime.Today

:-)

is enough,

I know it is a sample, but I wanted to show you that in VB Now is enough to
write.

Cor


Will that give any difference
 
Cor Ligthert said:
Is that not something as,

in C#
TimeSpan GiveTheTimeOfTheDay = DateTime.Now - DateTime.Today;
In VB
GiveTheTimeOfTheDay as TimeSpan = Now - DateTime.Today

:-)

is enough,

I think I'd still rather read:

TimeSpan giveTheTimeOfTheDay = DateTime.Now.TimeOfDay;
 
Well,

the original question was not how to get the time of the day but rather to
get the difference between two dates.

I simply used DateTime.Now and DateTime.Today as two example dates...

Best regards,
Henning Krause
 
Well heck Cor, you should have taken it all the way

Dim GiveTheTimeOfTheDay as TimeSpan = Now - Today

:-)

Kelly
 
Back
Top