473,386 Members | 1,819 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,386 software developers and data experts.

What is the easist way to caclulate the difference in days between two dates?

I would prefer not to use a reference to VB... just want an elegant way to
calculate days between two dates.

For example, 2004/12/31 and 2005/01/01 would show an elapsed time in days of
1.
Nov 16 '05 #1
2 1312
You could create a TimeSpan with one date taken away from the other (you
could use each ones Ticks property) and then the TimeSpan will give you the
difference in Days, Hours etc

Look up TimeSpan and you will find lots to fine tune what you need.
"Ryan" <nf*@nospam.com> wrote in message
news:uX*************@TK2MSFTNGP11.phx.gbl...
I would prefer not to use a reference to VB... just want an elegant way to
calculate days between two dates.

For example, 2004/12/31 and 2005/01/01 would show an elapsed time in days of 1.

Nov 16 '05 #2
"Ryan" <nf*@nospam.com> wrote in
news:uX*************@TK2MSFTNGP11.phx.gbl:
I would prefer not to use a reference to VB... just want an
elegant way to calculate days between two dates.

For example, 2004/12/31 and 2005/01/01 would show an elapsed
time in days of 1.


Ryan

DateTime start = new DateTime(2004, 12, 31);
DateTime end = new DateTime(2005, 1, 1);
TimeSpan ts = end - start;
int elapsedDays = ts.Days;
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
6
by: Ashish Sheth | last post by:
Hi All, In C#, How can I get the difference between two dates in number of months? I tried to use the Substract method of the DateTime class and it is giving me the difference in TimeSpan,From...
5
by: Simon Dean | last post by:
Probably being a little thick here, but when you subtract one date away from another, how do you convert the resultant value into a number of days... I guess I could easily / 60 / 60 / 24... but...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
2
by: David | last post by:
Hi, I have an order processing system in which I have an OrderDate and a Completion Date I want to print the difference in Weeks and Days between the two dates, i.e. if the completion date is...
4
by: Yotam | last post by:
Hi, I need some help with JS. I will be grateful, if you can help me out. I have two date fields (check in, check out) and "number of days" field. I want the script to calculate automatically...
2
by: Blackmore | last post by:
I am trying to use javascript to calculate the difference between two form inputted dates and return the result to another form object. When I load up the page with the function on my web browser...
8
by: Claudia Fong | last post by:
Hi, In VB we have DateDiff to calculate the days difference between 2 dates, I was wondering if we have something like that in C#? I want to calculate for example the days difference...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi, misters which the best method for get the difference (in days) of two dates. The hour (hh:mm) don't mind, would be 00:00 for all dates. 1.) fechaUno.Substract(fechaDos).Days 2.)
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.