473,573 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 18829
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****@discuss ions.microsoft. comwrote in message
news:48******** *************** ***********@mic rosoft.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 GiveTheTimeOfTh eDay = DateTime.Now - DateTime.Today;
In VB
GiveTheTimeOfTh eDay 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.infini tec.de>
schreef in bericht news:O1******** *****@TK2MSFTNG P02.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****@discuss ions.microsoft. comwrote in message
news:48******** *************** ***********@mic rosoft.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 GiveTheTimeOfTh eDay = DateTime.Now - DateTime.Today;
In VB
GiveTheTimeOfTh eDay as TimeSpan = Now - DateTime.Today

:-)

is enough,
I think I'd still rather read:

TimeSpan giveTheTimeOfTh eDay = DateTime.Now.Ti meOfDay;

--
Jon Skeet - <sk***@pobox.co m>
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.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
Cor Ligthert [MVP] <no************ @planet.nlwrote :
>Is that not something as,

in C#
TimeSpan GiveTheTimeOfTh eDay = DateTime.Now - DateTime.Today;
In VB
GiveTheTimeOfT heDay as TimeSpan = Now - DateTime.Today

:-)

is enough,

I think I'd still rather read:

TimeSpan giveTheTimeOfTh eDay = DateTime.Now.Ti meOfDay;

--
Jon Skeet - <sk***@pobox.co m>
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 GiveTheTimeOfTh eDay as TimeSpan = Now - Today

:-)

Kelly

Cor Ligthert [MVP] wrote:
Henning,

Is that not something as,

in C#
TimeSpan GiveTheTimeOfTh eDay = DateTime.Now - DateTime.Today;
In VB
GiveTheTimeOfTh eDay 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.infini tec.de>
schreef in bericht news:O1******** *****@TK2MSFTNG P02.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****@discuss ions.microsoft. comwrote in message
news:48******* *************** ************@mi crosoft.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
4088
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 minus 30mins to the present... eg effectively new and modified files: If DateDiff("n", subfolder.DateLastModified, sLastVisit ) < 30 Then.... etc...
8
5919
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 --------->could i get 2 years and 2 months and 1
6
16505
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 between values in the database and the current date. "No problem," thought I , "I'll just use the SQL DATEDIFF command." Heh! Well, the user...
1
7996
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 until completion: DateDiff("d",,) is TODAY the appropriate syntax for today's date? Could the function/expression even be set up that way, or do I...
4
11908
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 STARTINGDATE1 ENDINGDATE1 STARTINGDATE2
1
4970
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 blank. I've tried; > >DateDiff("y",-4,DateIn) and get errors > >Please any assistance would be greatly appreciated. >
7
15476
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 DateDiff in VB.NET which is only available in C# if you don't mind linking in Microsoft.VisualBasic.dll to your C# application. I wanted to avoid this...
5
7229
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 of the DateDiff in the VB.NET runtime. private int DateDiff( string Interval, DateTime Date1, DateTime Date2 ) { int intDateDiff = 0; TimeSpan...
6
7639
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
2752
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 like datediff(mm,date1,date2) datediff(mmm,date1,date2) datediff(month,date1,date2) datediff("mm",date1,date2) datediff("mmm",date1,date2)...
0
7747
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7669
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8036
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6361
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5262
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3702
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2167
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.