473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 18820
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CJM | last post by:
I have an ASP page that lists files and folders in a directory. I'm using a cookie to record the last time this page was visited, and I intend to show links that are created/modified from that date...
8
by: inamori | last post by:
I face that problems 07/01/2003 06/30/2006 ---------> it should be 3 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months 01/01/2003 03/01/2005 ...
6
by: Lofty | last post by:
Hi all. I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!) I need to work out the difference in days...
1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
5
by: sr | last post by:
Anyone know of a better way to simulate a datediff for C#, i.e., without referencing the VB.NET runtime? Only added the functionality that was needed for me so it is not the full implementation...
6
by: kevinjwilson | last post by:
I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
2
by: muddasirmunir | last post by:
i am using vb 6 , i had place two datepicker in form now i want to calcuate differcen of month in two date for this i used the function datediff i had try it withh many syntax but getting error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.