Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8
Default Difference between dates

Hi

I need to work out the difference between todays date and a previous date,
but I want the answer in this format:

Years & Months & Days

Is this possible? I can use today date minus the date and change the format
to show the difference in days. Any way to then change this to the needed
format?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,651
Default Difference between dates

You need the DATEDIF function:
http://www.cpearson.com/excel/datedif.htm
--
David Biddulph

"Khurum" wrote in message
...
Hi

I need to work out the difference between todays date and a previous date,
but I want the answer in this format:

Years & Months & Days

Is this possible? I can use today date minus the date and change the
format
to show the difference in days. Any way to then change this to the needed
format?



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,345
Default Difference between dates

Earlier date in A1, later date in A2:

=DATEDIF(A1,A2,"y")&" Years "&DATEDIF(A1,A2,"ym")&" Months
"&DATEDIF(A1,A2,"md")&" Days"

If you want the format to show the ampersands as well then include extra &'s
in the quoted text.

--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"Khurum" wrote in message
...
Hi

I need to work out the difference between todays date and a previous date,
but I want the answer in this format:

Years & Months & Days

Is this possible? I can use today date minus the date and change the
format
to show the difference in days. Any way to then change this to the needed
format?



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Difference between dates

=DATEDIF(A1,A2,"Y")&" years "&DATEDIF(A1,A2,"YM")&" months
"&DATEDIF(A1,A2,"MD")&" days"

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Khurum" wrote in message
...
Hi

I need to work out the difference between todays date and a previous date,
but I want the answer in this format:

Years & Months & Days

Is this possible? I can use today date minus the date and change the
format
to show the difference in days. Any way to then change this to the needed
format?



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,624
Default Difference between dates

No way to do it with format.

You can use DateDif() (e.g.:

A3: =DATEDIF(A1, A2, "y") & " & " & DATEDIF(A1, A2, "ym") & " & " &
DATEDIF(A1, A2, "md")

The problem is that "months" is a squirrelly concept. For instance, is
28 February 2007 one month and zero days after 31 January 2007? If so,
then is it *also* one month and zero days after 29 January?

DATEDIF bases month length on the length of the month in the first
argument. So the above formula returns

A1: 31 January 2007
A2: 28 February 2007
A3: 0 & 0 & 28

but then:

A1: 31 January 2007
A2: 1 March 2007
A3: 0 & 0 & -2


In article ,
Khurum wrote:

Hi

I need to work out the difference between todays date and a previous date,
but I want the answer in this format:

Years & Months & Days

Is this possible? I can use today date minus the date and change the format
to show the difference in days. Any way to then change this to the needed
format?



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,624
Default Difference between dates

See my other post to see why this may not return the values you expect...


In article ,
"Bob Phillips" wrote:

=DATEDIF(A1,A2,"Y")&" years "&DATEDIF(A1,A2,"YM")&" months
"&DATEDIF(A1,A2,"MD")&" days"

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,202
Default Difference between dates

I need to work out the difference between todays date and a previous date,
but I want the answer in this format:

Years & Months & Days

Is this possible? I can use today date minus the date and change the
format
to show the difference in days. Any way to then change this to the needed
format?


Your "format" is not exactly precise. Do you want your answer to look like
this...

5 & 3 & 21

or like this...

5 years & 3 months & 21 days

or did you want each date part in separate cells? Assuming you wanted the
second format I listed, try this formula...

=DATEDIF(A1,A2,"Y")&" years & "&DATEDIF(A1,A2,"YM")&" months &
"&DATEDIF(A1,A2,"MD")&" days"

Rick

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,202
Default Difference between dates

The problem is that "months" is a squirrelly concept. For instance, is
28 February 2007 one month and zero days after 31 January 2007? If so,
then is it *also* one month and zero days after 29 January?


No, 28-February-2007 is 28 days after 31-January-2007 and it is 30 days
after 29-January-2007 in the same way 30-April-2007 is 30 days after
31-March-2007. And, just like 1-May-2007 is 1 month and 0 days after
31-March-2007, 1-March-2007 should be 1 month and 0 days after
31-January-2007.

DATEDIF bases month length on the length of the month in the first
argument. So

A1: 31 January 2007
A2: 1 March 2007
A3: 0 & 0 & -2


Minus 2 days? That is just a ridiculous way to handle it. If you are
counting with months, then whenever you skip over a month, that is 1 month,
no matter how many days it has in it. DATEDIF has no trouble starting on the
last day of a 31-day month and skipping over a 30-day month to get to the
first of the following month, so why should the shorter month of February be
any different.

Rick

  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8
Default Difference between dates

Thanks to everyone. Problem completely solved.

"Rick Rothstein (MVP - VB)" wrote:

I need to work out the difference between todays date and a previous date,
but I want the answer in this format:

Years & Months & Days

Is this possible? I can use today date minus the date and change the
format
to show the difference in days. Any way to then change this to the needed
format?


Your "format" is not exactly precise. Do you want your answer to look like
this...

5 & 3 & 21

or like this...

5 years & 3 months & 21 days

or did you want each date part in separate cells? Assuming you wanted the
second format I listed, try this formula...

=DATEDIF(A1,A2,"Y")&" years & "&DATEDIF(A1,A2,"YM")&" months &
"&DATEDIF(A1,A2,"MD")&" days"

Rick


  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,268
Default Difference between dates


"Rick Rothstein (MVP - VB)" wrote in
message ...
The problem is that "months" is a squirrelly concept. For instance, is
28 February 2007 one month and zero days after 31 January 2007? If so,
then is it *also* one month and zero days after 29 January?


No, 28-February-2007 is 28 days after 31-January-2007 and it is 30 days
after 29-January-2007 in the same way 30-April-2007 is 30 days after
31-March-2007. And, just like 1-May-2007 is 1 month and 0 days after
31-March-2007, 1-March-2007 should be 1 month and 0 days after
31-January-2007.

DATEDIF bases month length on the length of the month in the first
argument. So

A1: 31 January 2007
A2: 1 March 2007
A3: 0 & 0 & -2


Minus 2 days? That is just a ridiculous way to handle it. If you are
counting with months, then whenever you skip over a month, that is 1
month, no matter how many days it has in it. DATEDIF has no trouble
starting on the last day of a 31-day month and skipping over a 30-day
month to get to the first of the following month, so why should the
shorter month of February be any different.




Did you try to your own formula with 01/31/07 in A1 and 03/01/07 in A2?
It returns

0 years & 1 months & -2 days

so are you saying that most people when asked how many months and days there
are between those dates would say 1 month and -2 days. Me thinks not and
that is the error in DATEDIF that John explained.


--

Regards,

Peo Sjoblom






  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,624
Default Difference between dates

In article ,
"Peo Sjoblom" wrote:

and that is the error in DATEDIF


Rather than an error in DATEDIF, which works very consistently, if not
always the way we want it to), it's inherent in *any* deterministic
algorithm that I've ever seen used.

"Month", as a unit of time, is just too fluid a concept to be captured
algorithmically.

For instance, using Rick's definition, 1 March is 1 month and 0 days
after 31 January. One way of interpreting that is that 1 March is also 1
month and 0 days after 28 January, 29 January, and 30 January. That way
leads to madness when one wants a single result when trying to calculate
a date 1 month prior to 1 March.

That definition also causes strangeness when the first month is shorter
than the final one:

Start Date End Date Months/Days
28 Feb 28 Mar 0/28?
28 Feb 29 Mar 0/29? or 1/1?
28 Feb 30 Mar 0/30? or 1/2?
28 Feb 31 Mar 0/31? or 1/3?
28 Feb 1 Apr 1/0? or 1/4?
01 Mar 01 Apr 0/30? or 1/0?

in either case there's a discontinuity in the function...

Those of us who've been around here a while may remember herculean
efforts lead by Norman Harker to better DATEDIF with a self-consistent
algorithm, and the frustration of not being able to do so.
  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,268
Default Difference between dates


"JE McGimpsey" wrote in message
...
In article ,
"Peo Sjoblom" wrote:

and that is the error in DATEDIF


Rather than an error in DATEDIF, which works very consistently, if not
always the way we want it to), it's inherent in *any* deterministic
algorithm that I've ever seen used.


true, I should have expressed myself better.

"Month", as a unit of time, is just too fluid a concept to be captured
algorithmically.

For instance, using Rick's definition, 1 March is 1 month and 0 days
after 31 January. One way of interpreting that is that 1 March is also 1
month and 0 days after 28 January, 29 January, and 30 January. That way
leads to madness when one wants a single result when trying to calculate
a date 1 month prior to 1 March.

That definition also causes strangeness when the first month is shorter
than the final one:

Start Date End Date Months/Days
28 Feb 28 Mar 0/28?
28 Feb 29 Mar 0/29? or 1/1?
28 Feb 30 Mar 0/30? or 1/2?
28 Feb 31 Mar 0/31? or 1/3?
28 Feb 1 Apr 1/0? or 1/4?
01 Mar 01 Apr 0/30? or 1/0?

in either case there's a discontinuity in the function...

Those of us who've been around here a while may remember herculean
efforts lead by Norman Harker to better DATEDIF with a self-consistent
algorithm, and the frustration of not being able to do so.



Yes I remember that



--

Regards,

Peo Sjoblom


  #13   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Difference between dates



"David Biddulph" wrote:

You need the DATEDIF function:
http://www.cpearson.com/excel/datedif.htm
--
David Biddulph

"Khurum" wrote in message
...
Hi

I need to work out the difference between todays date and a previous date,
but I want the answer in this format:

Years & Months & Days

Is this possible? I can use today date minus the date and change the
format
to show the difference in days. Any way to then change this to the needed
format?



Thanks to you all,

I have just moved from Lotus and didn't think my "Birthday Sheet" would
work, Years, Months & Days. But thanks to you I have found the hidden
"Datedif" again.
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
Difference of two dates Zafar Excel Worksheet Functions 3 July 26th 07 08:44 AM
Difference of two dates sajan chauhan Excel Discussion (Misc queries) 3 June 5th 07 04:47 AM
difference between dates Clash Excel Discussion (Misc queries) 4 May 26th 06 08:02 AM
difference between dates dcccgoose Excel Discussion (Misc queries) 3 May 15th 06 03:34 AM
difference between two dates dhouston1000 Excel Discussion (Misc queries) 2 August 24th 05 11:19 AM


All times are GMT +1. The time now is 04:16 AM.

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

About Us

"It's about Microsoft Excel"