3. Date Manipulation formulas
3.1 Add/Subtract month from a given date
Very often, you will have business problems where you have to add or subtract month
from a given date. One scenario is calculation for EMI Date.
Say, you have a date of 11/15/23 (MM/DD/YY) in A1 and you want to add number of
months which is contained in Cell B1.
The formula in this case would be
Now, you want to subtract month which is contained in Cell B1.
3.2 Add/Subtract year from a given date
In many business problems, you might encounter situations where you will need to add or
subtract years from a given date.
Let's say A1 contains Date and B1 contains numbers of years.
If you want to add Years to a given date, formulas would be
If you want to subtract Years from a given date, formulas would be
3.3 Convert a number to a month name
Use below formula to generate named 3 lettered month like Jan, Feb....Dec
Replace "mmm" with "mmmm" to generate full name of the month like January, February....December in any of the formulas in this post.
3.4 Convert date to a calendar quarter
Assuming date is in Cell A1. You want to convert it into a quarter (1, 2, 3 & 4). Jan to Mar is 1, Apr to Jun is 2, Jul to Sep is 3 and Oct to Dec is 4.
3.5 Convert date to a indian financial year quarter
Assuming date is in Cell A1. You want to convert it into a Indian Financial Year Quarter. Jan to Mar is 4, Apr to Jun is 1, Jul to Sep is 2 and Oct to Dec is 3.
3.6 Calculate age from given Birthday
3.7 Number to date format conversion
If you have numbers like 010216 and you want to convert this to date format, then the following formula can be used
Note – Minimum 5 digits are needed for above formula to work
If you have numbers like 01022016 and you want to convert this to date format, then the
following formula can be used.
Note – Minimum 7 digits are needed for above formula to work
3.8 Number to time format conversion
If you have numbers like 1215 and you want to convert this to hh:mm format, then the following formula can be used
Note – Minimum 3 digits are needed for above formula to work To convert to hh:mm:ss format
Note – Minimum 5 digits are needed for above formula to work
3.9 First day of month for a given date
Suppose you have been given a date say 11/15/23 (MM/DD/YY) and you want to calculate
the first day of the Current Month. Hence, you want to achieve a result of 11/1/2023
(MM/DD/YY).
The formulas to be used
3.10 Count any day of the week between 2 dates (e.g Monday)
Suppose A1 = 23-Jan-23 and A2 = 10-Nov-23. To find number of Mondays between these two dates
“Mon” can be replaced with any other day of the week as per need.
3.11 Find next week of a given day
There are 2 scenarios in this case. For example, if today’s date is 2-Jan-17 (Monday) and I try to find the next Monday, I can get either 2-Jan-17 or 9-Jan-17 as per need. For Tuesday to Sunday, it is not a problem as they come after 2-Jan-17 only.
3.12 Find previous week of a given day
There are 2 scenarios in this case. For example, if today’s date is 2-Jan-17 (Monday) and I try to find the previous Monday, I can get either 2-Jan-17 or 26-Dec-16 as per need. For Tuesday to Sunday, it is not a problem as they come prior to 2-Jan-17 only.
3.13 Find last day of month for a given date
Suppose, you are given a date say 10/22/23 (MM/DD/YY) and we want to have the last date of the month for the given date. Hence, you needs an answer of 10/31/23. The formulas to be used in this case
3.14 Find number of days in a month
Suppose, you have been given a date say 15-Nov-23 and you have to determine how many
days this particular month contains.
The formula which you need to use in the above case would be
Explanation - EOMONTH(A1,0) gives the last date of the month and DAY function extract that particular Day from the last date of the month.
3.15 Check if given Year is a Leap Year
Let's say that A1 contains the year. To know whether it is a Leap Year or not, use following formula
TRUE means that it is Leap Year and FALSE means that this is not a Leap Year.
3.16 Last working day of the month for a given date
If A1 holds a date, the formula for calculating last Working Day of the month would be
The above formula assumes that your weekends are Saturday and Sunday. But, if your weekends are different (e.g. in gulf countries), you can use following formula
Where 0000110 is a 7 character string, 1 represents a weekend and 0 is a working day. First
digit is Monday and last digit is Sunday. The above example is for Gulf countries where
Friday and Saturday are weekends.
You also have option to give a range which has holidays. In that case, your formula would
Where range D1:D10 contains the list of holidays.
3.17 First working day of the month for a given date
If A1 contains a date, then formula for First Working Day of the month would be
The above formula assumes that your weekends are Saturday and Sunday. But, if your weekends are different (e.g. in gulf countries), you can use following formula
Where 0000110 is a 7 character string, 1 represents a weekend and 0 is a working day. First
digit is Monday and last digit is Sunday. The above example is for Gulf countries where
Friday and Saturday are weekends.
You also have option to give a range which has holidays. In that case, your formula would
become
Where range D1:D10 contains the list of holidays.
3.18 Date for Nth Day of a given Year
Suppose A1 contains the Year and you are asked to find 69th day of the year which is contained in A2. Then formula for finding Nth day of the year would be
3.19 Extract Date and Time from Date Timestamp
Suppose you have a date timestamp value in cell A1 -
A1 = 06/14/23 10:15 PM
And you want to extract date and time out of this.
To extract date, use following formula and format the result cell as date
To extract time, use following formula and format the result cell as time
3.20 Get Financial Year
A good number of countries don't follow calendar year as the financial year. For example,
India's financial year start is 1-Apr and finishes on 31-Mar. Hence, currently (20-Feb-23),
the financial year is 2022-23 (It is also written as FY23). On 1-Apr-23, it will become 2022-
23 (It is also written as FY23).
Now if a date is given, then following formula can be used to derive 2022-23 kind of result.
To generate FY16 kind of result, following formula can be used
3.21 First working day of the year
If a year is given in A1 say 2022, below formula can be used to know the first working day of the year (format the result as date)
The above formula assumes that your weekends are Saturday and Sunday. But, if your weekends are different (e.g. in gulf countries), you can use following formula
Where 0000110 is a 7 character string, 1 represents a weekend and 0 is a working day. First
digit is Monday and last digit is Sunday. The above example is for Gulf countries where
Friday and Saturday are weekends.
You also have option to give a range which has holidays. In that case, your formula would
become
Where range D1:D10 contains the list of holidays.
3.22 Last working day of the year
If a year is given in A1 say 2022, below formula can be used to know the last working day of the year (format the result as date)
The above formula assumes that your weekends are Saturday and Sunday.
But, if your weekends are different (e.g. in gulf countries), you can use following formula
Where 0000110 is a 7 character string, 1 represents a weekend and 0 is a working day. First
digit is Monday and last digit is Sunday. The above example is for Gulf countries where
Friday and Saturday are weekends.
You also have option to give a range which has holidays. In that case, your formula would
become
Where range D1:D10 contains the list of holidays.
3.23 Convert Gregorian Date to Julian Date
Q. First what is a Julian Date?
A. A Julian date has either 7 digits or 5 digits date and these are generally used in old IT
legacy systems.
7 Digits - YYYYDDD - 2022092 (This is 1-Apr-2022. 92 means that this is 92nd day from 1-
Jan in that year)
5 Digits - YYDDD - 22092
Q. What formulas to use to convert Gregorian Dates to Julian Dates?
A. For 7 Digits, use following formula
3.24 Convert Julian Date to Gregorian Date
For 7 Digits Julian Dates, following formula should be used
For 5 Digits Julian Dates, following formula should be used depending upon which century (Note - Julian dates are most likely to fall into 20th Century)
Note - 19 or 20 can be replaced with some IF condition to put in right 19 or 20 depending upon the year. For example, year 82 is more likely to be in 20th century where year 15 is more likely to be in 21st century.