Need help with the following formula:
A1=2010/01/12
B1==DATE(LEFT(A1,4)+1,MID(A1,5,2),RIGHT(A1,2))
Why I'm getting 4020/02/28 as the result in B1? What I'm looking for is to add 1-Year to the date in A1. Please advise....
To directly answer your question...
In Excel dates are really just numbers formatted to look like dates. These numbers are the count of days since a base date. The default base date is Jan 1 1900. The numerical value given to dates is commonly referred to as the date serial number. Jan 1 1900 has a value of 1 and each day since that date the numeric value increases by 1.
So:
1/1/1900 = date serial number 1
1/2/1900 = date serial number 2
1/3/1900 = date serial number 3
1/4/1900 = date serial number 4
1/5/1900 = date serial number 5
1/1/1975 = date serial number 27395
1/1/2000 = date serial number 36526
1/1/2011 = date serial number 40544
When you enter a date in a cell Excel recognizes the entry as a date and automatically formats the entry as a date. However, the true value of that entry is the date serial number.
If you enter the date 1/1/2011 in cell A1 the cell displays as 1/1/2011 but the true value of that cell is the date serial number 40544. You can see this by changing the cell format to General or Number.
So, when you do calculations based on the "date" you're actually doing the calculation on the true value of the cell, the date serial number.
In your case here's how it breaks out:
A1 = 2010/01/12 (y/m/d) format
The true value of the cell, the date serial number, is 40190.
Taking apart the DATE function we get:
LEFT(A1,4)+1 ... 4019 + 1 = 4020
MID(A1,5,2) ... 0
RIGHT(A1,2) ... 90
Then:
DATE(4020,0,90) = 4020/2/28
Ok, this part will be hard to understand....
There is no month 0 or day 90. The DATE function is "smart" and can adjust for these unusual values.
The 0th month actually refers to the previous month. In this case the 0th month is actually December 4019.
In effect it would look like this:
DATE(4019,12,90)
That still looks goofy, don't it?
Well, the DATE function does the same thing with the days. There is no day 90 BUT if you add 90 days to 4019/12/1 (inclusive) you end up at 4020/2/28.
So:
A1: 2010/01/12
B1: =DATE(LEFT(A1,4)+1,MID(A1,5,2),RIGHT(A1,2))
= 4020/2/28
Which is the correct result albeit not the expected result.