Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
ady_sandu
 
Posts: n/a
Default How do I calculate the difference between 2 dates (m,d,y) ?

How do I calculate the difference between 2 dates (m,d,y) ?
For example :
date1 = 19 feb 1999
date2 = 07 ian 2005
difference = **days, **months, **years.
thank you!
  #2   Report Post  
ScottO
 
Posts: n/a
Default

This may not be the *best* way, but it looks like it works ...

In A1 put Date1 (eg 19 Feb 1999)
In A2 put Date2 (eg 07 Jan 2005)
In B1 put the formula =INT(YEARFRAC(A1,A2,1))
In B2 put the formula =INT((YEARFRAC(A1,A2,1)-B1)*12)
In B3 put the formula =A2-DATE(YEAR(A1)+B1,MONTH(A1)+B2,DAY(A1))
In C1 put the text "Years"
In C2 put the text "Months"
In C3 put the text "Days"

If you need to get the result all into one cell, you can make a
compound formula, or concatenate the results as you wish.

HTH
ScottO

"ady_sandu" wrote in message
...
| How do I calculate the difference between 2 dates (m,d,y) ?
| For example :
| date1 = 19 feb 1999
| date2 = 07 ian 2005
| difference = **days, **months, **years.
| thank you!


  #3   Report Post  
ady_sandu
 
Posts: n/a
Default

the function *INT(YEARFRAC(A1,A2,1))* it is not recognized by excel...

"ScottO" wrote:

This may not be the *best* way, but it looks like it works ...

In A1 put Date1 (eg 19 Feb 1999)
In A2 put Date2 (eg 07 Jan 2005)
In B1 put the formula =INT(YEARFRAC(A1,A2,1))
In B2 put the formula =INT((YEARFRAC(A1,A2,1)-B1)*12)
In B3 put the formula =A2-DATE(YEAR(A1)+B1,MONTH(A1)+B2,DAY(A1))
In C1 put the text "Years"
In C2 put the text "Months"
In C3 put the text "Days"

If you need to get the result all into one cell, you can make a
compound formula, or concatenate the results as you wish.

HTH
ScottO

"ady_sandu" wrote in message
...
| How do I calculate the difference between 2 dates (m,d,y) ?
| For example :
| date1 = 19 feb 1999
| date2 = 07 ian 2005
| difference = **days, **months, **years.
| thank you!



  #4   Report Post  
ScottO
 
Posts: n/a
Default

Sorry ady_, I should have mentioned that the "YearFrac" function is
an add-in.
All you need to do is load the Analysis ToolPak add-in and it'll work
fine.
Go Tools\Add-ins and check the box next to Analysis ToolPak, then
click OK.
Rgds,
ScottO

"ady_sandu" wrote in message
...
| the function *INT(YEARFRAC(A1,A2,1))* it is not recognized by
excel...
|
| "ScottO" wrote:
|
| This may not be the *best* way, but it looks like it works ...
|
| In A1 put Date1 (eg 19 Feb 1999)
| In A2 put Date2 (eg 07 Jan 2005)
| In B1 put the formula =INT(YEARFRAC(A1,A2,1))
| In B2 put the formula =INT((YEARFRAC(A1,A2,1)-B1)*12)
| In B3 put the formula =A2-DATE(YEAR(A1)+B1,MONTH(A1)+B2,DAY(A1))
| In C1 put the text "Years"
| In C2 put the text "Months"
| In C3 put the text "Days"
|
| If you need to get the result all into one cell, you can make a
| compound formula, or concatenate the results as you wish.
|
| HTH
| ScottO
|
| "ady_sandu" wrote in
message
| ...
| | How do I calculate the difference between 2 dates (m,d,y) ?
| | For example :
| | date1 = 19 feb 1999
| | date2 = 07 ian 2005
| | difference = **days, **months, **years.
| | thank you!
|
|
|


  #5   Report Post  
ScottO
 
Posts: n/a
Default

If you don't like my answer, and I wouldn't blame you ;) ...
Take a look at this link http://www.meadinkent.co.uk/xl_birthday.htm
Rgds,
ScottO

"ScottO" wrote in
message ...
| Sorry ady_, I should have mentioned that the "YearFrac" function is
| an add-in.
| All you need to do is load the Analysis ToolPak add-in and it'll
work
| fine.
| Go Tools\Add-ins and check the box next to Analysis ToolPak, then
| click OK.
| Rgds,
| ScottO
|
| "ady_sandu" wrote in message
| ...
| | the function *INT(YEARFRAC(A1,A2,1))* it is not recognized by
| excel...
| |
| | "ScottO" wrote:
| |
| | This may not be the *best* way, but it looks like it works ...
| |
| | In A1 put Date1 (eg 19 Feb 1999)
| | In A2 put Date2 (eg 07 Jan 2005)
| | In B1 put the formula =INT(YEARFRAC(A1,A2,1))
| | In B2 put the formula =INT((YEARFRAC(A1,A2,1)-B1)*12)
| | In B3 put the formula
=A2-DATE(YEAR(A1)+B1,MONTH(A1)+B2,DAY(A1))
| | In C1 put the text "Years"
| | In C2 put the text "Months"
| | In C3 put the text "Days"
| |
| | If you need to get the result all into one cell, you can make a
| | compound formula, or concatenate the results as you wish.
| |
| | HTH
| | ScottO
| |
| | "ady_sandu" wrote in
| message
| | ...
| | | How do I calculate the difference between 2 dates (m,d,y) ?
| | | For example :
| | | date1 = 19 feb 1999
| | | date2 = 07 ian 2005
| | | difference = **days, **months, **years.
| | | thank you!
| |
| |
| |
|
|




  #6   Report Post  
Myrna Larson
 
Posts: n/a
Default

This will NOT always work correctly.

Errors are most likely when the 2nd date is very close to the anniversary
date. For example, with the dates Sep 29, 2000 and Sep 29, 2005. The result is
4 years, 11 months, and 31 days, instead of 5 years, 0 months, and 0 days.

(OTOH, with the first date Sep 29, 2001, you do get 4 years exactly.)

Based on much experimentation that Norman Harker and I did some time ago, the
"problems" arise from the bizarre way in which this function calculates the
number of days in year (the average of the year lengths starting with the
calendar year in which the 1st date falls and ending with the calendar year in
which the last day falls). We concluded that YEARFRAC was intended for
calculation of time spans less of than a year, and even then you have problems
if the dates are in two different years and one of them is a leap year.


On Thu, 29 Sep 2005 17:34:06 +1000, "ScottO"
wrote:

This may not be the *best* way, but it looks like it works ...

In A1 put Date1 (eg 19 Feb 1999)
In A2 put Date2 (eg 07 Jan 2005)
In B1 put the formula =INT(YEARFRAC(A1,A2,1))
In B2 put the formula =INT((YEARFRAC(A1,A2,1)-B1)*12)
In B3 put the formula =A2-DATE(YEAR(A1)+B1,MONTH(A1)+B2,DAY(A1))
In C1 put the text "Years"
In C2 put the text "Months"
In C3 put the text "Days"

If you need to get the result all into one cell, you can make a
compound formula, or concatenate the results as you wish.

HTH
ScottO

"ady_sandu" wrote in message
...
| How do I calculate the difference between 2 dates (m,d,y) ?
| For example :
| date1 = 19 feb 1999
| date2 = 07 ian 2005
| difference = **days, **months, **years.
| thank you!

  #7   Report Post  
Roger Govier
 
Posts: n/a
Default

Hi Ady

One way would be to use the little documented DATEDIF function

With your first date in A1 and your second date in A2
=DATEDIF(A1,A2,"md")&" days, "&DATEDFIF(A1,A2,"ym")&" months,
"&DATEDIF(A1,A2,"y")&" years"

Regards

Roger Govier


ady_sandu wrote:
How do I calculate the difference between 2 dates (m,d,y) ?
For example :
date1 = 19 feb 1999
date2 = 07 ian 2005
difference = **days, **months, **years.
thank you!

  #8   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

On Thu, 29 Sep 2005 09:15:42 +0100, Roger Govier
wrote:

Hi Ady

One way would be to use the little documented DATEDIF function

With your first date in A1 and your second date in A2
=DATEDIF(A1,A2,"md")&" days, "&DATEDFIF(A1,A2,"ym")&" months,
"&DATEDIF(A1,A2,"y")&" years"

Regards

Roger Govier



One of my peeves with the DATEDIF function is that it can give strange results
under certain circumstances. For example:

A1: 31 Jan 2005
A2 1 Mar 2007

-2 days, 1 months, 2 years


--ron
  #9   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

On Wed, 28 Sep 2005 22:04:02 -0700, ady_sandu
wrote:

How do I calculate the difference between 2 dates (m,d,y) ?
For example :
date1 = 19 feb 1999
date2 = 07 ian 2005
difference = **days, **months, **years.
thank you!


Since both years and months have varying numbers of days, how you calculate the
differences depends on how you define these terms and how you want to calculate
the differences.

For example:

What result do you want for the following pairs of dates?

Start End
1/31/2005 3/1/2005

2/1/2005 3/1/2005

1/31/2005 5/1/2005

1/15/2005 3/15/2005


--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I calculate duration between two dates and times in excel? Robin CSM002 Excel Discussion (Misc queries) 3 May 13th 23 07:42 PM
Calculate Difference b/e 2 dates. scharee New Users to Excel 2 August 2nd 05 04:28 PM
Calculate numbers between 2 dates Rajiv@Ivey Excel Discussion (Misc queries) 0 May 17th 05 06:25 PM
Calculate difference between two dates Trainer Excel Worksheet Functions 1 February 11th 05 02:04 PM
How do I calculate difference in days & hours between two dates e. probi2 Excel Worksheet Functions 1 January 12th 05 03:59 PM


All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"