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

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.
 
H

Henning Krause [MVP - Exchange]

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
 
C

Cor Ligthert [MVP]

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
 
J

Jon Skeet [C# MVP]

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;
 
H

Henning Krause [MVP - Exchange]

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
 
K

Kelly Ethridge

Well heck Cor, you should have taken it all the way

Dim GiveTheTimeOfTheDay as TimeSpan = Now - Today

:)

Kelly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top