P: n/a

Hi everyone,
is there a function that calculates the exact amount of Years, Months, and
Days between two days?
TimeDiff is not good enough, since it calculates, for example:
Date 1: Dec. 31st 2003
Date 2: Jan 1st 2004
The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 year, 1
month, 1 day.
Is there a funcion, or rutine, or does anyone know a good way to achieve the
desired result?
Thanks, from Spain  
Share this Question
P: n/a

Hi Juan,
Try subtracting two DateTime variables and you'll end up with TimeSpan
structure.

Miha Markic [MVP C#]  RightHand .NET consulting & software development
miha at rthand com www.rthand.com
"Juan" <ju*********@hotmail.com> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl... Hi everyone,
is there a function that calculates the exact amount of Years, Months, and Days between two days?
TimeDiff is not good enough, since it calculates, for example:
Date 1: Dec. 31st 2003 Date 2: Jan 1st 2004
The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 year,
1 month, 1 day.
Is there a funcion, or rutine, or does anyone know a good way to achieve
the desired result?
Thanks, from Spain
 
P: n/a

Subtract one datetime from another to return a TimeSpan. You can get the
time accurate to the millisecond.

Bob Powell [MVP]
Visual C#, System.Drawing
All you ever wanted to know about ListView custom drawing is in Well Formed. http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*
The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.isageek.com/siteFeeder...aspx?FeedId=41
*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*
"Juan" <ju*********@hotmail.com> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl... Hi everyone,
is there a function that calculates the exact amount of Years, Months, and Days between two days?
TimeDiff is not good enough, since it calculates, for example:
Date 1: Dec. 31st 2003 Date 2: Jan 1st 2004
The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 year,
1 month, 1 day.
Is there a funcion, or rutine, or does anyone know a good way to achieve
the desired result?
Thanks, from Spain
 
P: n/a

But I canīt get the numbers of years and mohts transcurred from a TimeSpan,
only the number of days, and that doesnīt solve the Dec 31st 2001 to Jan 1st
2004 problem. I will find out the number of days, but not the number of
months or years.
Bob Powell [MVP] wrote:
:: Subtract one datetime from another to return a TimeSpan. You can get
:: the time accurate to the millisecond.
::
:: 
:: Bob Powell [MVP]
:: Visual C#, System.Drawing
::
:: All you ever wanted to know about ListView custom drawing is in Well
:: Formed. http://www.bobpowell.net/currentissue.htm
::
:: Answer those GDI+ questions with the GDI+ FAQ
:: http://www.bobpowell.net/gdiplus_faq.htm
::
:: *RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*
::
:: The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
:: Windows Forms Tips and Tricks:
:: http://www.bobpowell.net/tipstricks.xml Bob's Blog:
:: http://royo.isageek.com/siteFeeder...aspx?FeedId=41
::
:: *RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*
::
::
::
::
::
:: "Juan" <ju*********@hotmail.com> wrote in message
:: news:OB**************@TK2MSFTNGP10.phx.gbl...
::: Hi everyone,
:::
::: is there a function that calculates the exact amount of Years,
::: Months, and Days between two days?
:::
::: TimeDiff is not good enough, since it calculates, for example:
:::
::: Date 1: Dec. 31st 2003
::: Date 2: Jan 1st 2004
:::
::: The real difference is 0 years, 0 months, 1 day. DateDiff returns 1
::: year, 1 month, 1 day.
:::
::: Is there a funcion, or rutine, or does anyone know a good way to
::: achieve the desired result?
:::
::: Thanks, from Spain  
P: n/a

"Juan" <ju*********@hotmail.com> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl... Hi everyone,
is there a function that calculates the exact amount of Years, Months, and Days between two days?
TimeDiff is not good enough, since it calculates, for example:
Date 1: Dec. 31st 2003 Date 2: Jan 1st 2004
The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 year,
1 month, 1 day.
Is there a funcion, or rutine, or does anyone know a good way to achieve
the desired result?
You need to think a little more about whether your "desired result" makes
sense.
Months and Years are not fixed Timespans. Given 2 DateTime's the rule for
DateDiff is, and has to be, that the difference in years between the 2 dates
is the number of times you cross the "year boundary" (Jan 1st 12:00 am),
when traveling from the first date to the second.
Other rules are sometimes used, but they have their own difficulties.
For instance what is the difference in months between
Date 1: Jan. 31st 2003
Date 2: Feb. 28st 2003
?
The interval is 28 days long.
January has 31 days, so is the differnece is 0?
February has 28 days, so is the differnece is 1?
Or is a month defined as a 30 day timespan, so is the difference is 0?
What about
Date 1: Jan. 31st 2004
Date 2: Feb. 28st 2004
?
January has 31 days, and February has 29 days so is the difference is 0?
And what about
Date 1: Feb. 28st 2003
Date 2: Jan. 31st 2003
?
is DateDiff(d1,d2) = DateDiff(d2,d1)?
David  
P: n/a

Juan wrote: But I canīt get the numbers of years and mohts transcurred from a TimeSpan, only the number of days, and that doesnīt solve the Dec 31st 2001 to Jan 1st 2004 problem. I will find out the number of days, but not the number of months or years.
you can use VB.NET's DateDiff() function. Either wrap it in a class
that you can easily call from C# or call it directly by referencing the
Microsoft.VisualBasic assembly  it's in the
Microsoft.VisualBasic.DateAndTime class. Bob Powell [MVP] wrote: :: Subtract one datetime from another to return a TimeSpan. You can get :: the time accurate to the millisecond. :: ::  :: Bob Powell [MVP] :: Visual C#, System.Drawing :: :: All you ever wanted to know about ListView custom drawing is in Well :: Formed. http://www.bobpowell.net/currentissue.htm :: :: Answer those GDI+ questions with the GDI+ FAQ :: http://www.bobpowell.net/gdiplus_faq.htm :: :: *RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS* :: :: The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml :: Windows Forms Tips and Tricks: :: http://www.bobpowell.net/tipstricks.xml Bob's Blog: :: http://royo.isageek.com/siteFeeder...aspx?FeedId=41 :: :: *RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS* :: :: :: :: :: :: "Juan" <ju*********@hotmail.com> wrote in message :: news:OB**************@TK2MSFTNGP10.phx.gbl... ::: Hi everyone, ::: ::: is there a function that calculates the exact amount of Years, ::: Months, and Days between two days? ::: ::: TimeDiff is not good enough, since it calculates, for example: ::: ::: Date 1: Dec. 31st 2003 ::: Date 2: Jan 1st 2004 ::: ::: The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 ::: year, 1 month, 1 day. ::: ::: Is there a funcion, or rutine, or does anyone know a good way to ::: achieve the desired result? ::: ::: Thanks, from Spain

mikeb   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 8118
 replies: 5
 date asked: Nov 16 '05
