Today, a financial, MM asked me Excel calculation seniority problem, I think, I really do not ah. The test, write case, report progress, statistical bugs are generally used in Excel, and really did not have to calculate the date of seniority birthdays and so on.
Her request was:
Incredibly not, think half a day to think of 2 schemes: 1, write a script to her in Perl; 2, the information into the database, with the SELECT statement query and then export the results;
Later, think carefully, this does not meet her requirements, people want to use Excel to solve. So I started looking for Excel function, about date processing.
In general programming languages and databases, there are functions to get the current date and string processing, so I follow this idea to find. (She did not ask for a 3.5-year seniority, only for a full month)
The function that Excel obtains the current date is:
Today () Gets the system date display:
Now () Get system date and current time
Because no system time is required, choose today ()
Time processing function: Datedif (start_date,end_date,unit)
The start_date and end_date parameters of the DATEDIF function are the starting and ending dates, and the unit is what the user expects the DATEDIF function to return. Unit units have six kinds,
The distinction is: "Y": All Year "M": Full Month "D": All Day "YM": The number of months in less than a year "YD": Days in less than a year "MD": Days less than one months to notice is
Note: 1. The DATEDIF function must include double quotes when entering the unit parameter. 2.start_date
Datedif ("2001-09-01", "2013-01-01", "Y") 11
Datedif ("2001-09-01", "2013-01-01", "YM") 4
Datedif ("2001-09-01", "2013-01-01", "MD") 0
Datedif ("2001-09-01", "2013-01-01", "YD") 122
The rest is easy and needs to be
Excel Connectors &
Get Datedif (a2,b2, "Y") & "-" &datedif (A2,B2, "YM") & "-" &datedif (A2,B2, "MD") work all the year round
What is the date of birth of the ID number?
First, determine if the ID number is 18 digits, Len (str).
=if (len (str) =18,true,false)
Intercept the year of birth mid (a2,7,4) from the seventh digit of Cell A2, intercept 4 (7, 8, 9, 10)