Calculating dates (prior year)

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Calculating dates (prior year)

Post by VegasNath »

Hi,
Please can anyone explain why using this formula works fine for the current year but not the prior year?
Capture3.JPG
The format of column A is general, being an import from an external data source.
You do not have the required permissions to view the files attached to this post.
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78650
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Calculating dates (prior year)

Post by HansV »

The formula only works "fine" for the current month - look at the result in row 3! The formula uses the date format yyyymmdd as a number, e.g. today is 20110212 i.e. 20,110,212 = twenty million one hundred and ten thousand two hundred and twelve. This is not a number of days in any meaningful sense of the word.
Best wishes,
Hans

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: Calculating dates (prior year)

Post by VegasNath »

I see what you mean.
Is there a way to convert A1 to a meaningful value in order to calculate?
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78650
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Calculating dates (prior year)

Post by HansV »

Yes, for example

=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))

or

=DATE(TRUNC(A1/10000),MOD(A1/100,100),MOD(A1,100))
Best wishes,
Hans

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: Calculating dates (prior year)

Post by VegasNath »

Great, Thanks Hans.
=VALUE(TODAY())-DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))
..... appears to be accurate. :cheers:
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78650
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Calculating dates (prior year)

Post by HansV »

You don't need VALUE here.

=TODAY()-DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))

should work - if Excel formats the result as a date, just clear the formatting (or set the number format to General).
Best wishes,
Hans

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: Calculating dates (prior year)

Post by VegasNath »

:thankyou:
:wales: Nathan :uk:
There's no place like home.....