469,306 Members | 1,789 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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

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.
Jun 21 '07 #1
5 18577
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

"Andrew" <An****@discussions.microsoft.comwrote in message
news:48**********************************@microsof t.com...
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.
Jun 21 '07 #2
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
"Henning Krause [MVP - Exchange]" <ne***************@this.infinitec.de>
schreef in bericht news:O1*************@TK2MSFTNGP02.phx.gbl...
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

"Andrew" <An****@discussions.microsoft.comwrote in message
news:48**********************************@microsof t.com...
>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.

Jun 21 '07 #3
Cor Ligthert [MVP] <no************@planet.nlwrote:
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;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 21 '07 #4
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

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Cor Ligthert [MVP] <no************@planet.nlwrote:
>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;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 22 '07 #5
Well heck Cor, you should have taken it all the way

Dim GiveTheTimeOfTheDay as TimeSpan = Now - Today

:-)

Kelly

Cor Ligthert [MVP] wrote:
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
"Henning Krause [MVP - Exchange]" <ne***************@this.infinitec.de>
schreef in bericht news:O1*************@TK2MSFTNGP02.phx.gbl...
>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

"Andrew" <An****@discussions.microsoft.comwrote in message
news:48**********************************@microso ft.com...
>>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.

Jun 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by inamori | last post: by
6 posts views Thread by Lofty | last post: by
4 posts views Thread by Paolo | last post: by
5 posts views Thread by sr | last post: by
6 posts views Thread by kevinjwilson | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.