Avatar of starlite551
starlite551
Flag for India asked on

Which is the best way to find Date difference between two dates in C#?

Please submit a code snippet which is most efficient one.. I know about TimeSpan Class Method is there any other method thats more effective?
C#Programming Languages-Other

Avatar of undefined
Last Comment
existenz2

8/22/2022 - Mon
rockiroads

Not that I know off. I thought it better to use what is available in dotnet and for c# that seems to be it.

A little discussion on that here including an alternative using vb namespaces http://www.c-sharpcorner.com/UploadFile/DipalChoksi/DateDiff_CS_DC09132006172429PM/DateDiff_CS_DC.aspx
joriszwaenepoel

dim date1 as datetime = ...
dim date2 as datetime = ...

dim datediff = date2.subtract(date1)

This gives you a TimeSpan object with all the information.  What makes you think this is not efficient?
SOLUTION
Naman Goel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
existenz2

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61