Date Calculations

Location:   http://www.mvps.org/dmcritchie/excel/datecalc.htm
Home page: http://www.mvps.org/dmcritchie/excel/excel.htm
[View without Frames]

ABCDE
Dates(Dates are shown in US/Canada format mm/dd/yyyy) Formula used
starting date01/19/19982Mon=WEEKDAY(B3,1)
add days18207/20/1998Mon=B3+B4
add months607/19/1998Sun=DATE(YEAR(B3),MONTH(B3)+B5,DAY(B3))
add years101/30/1999Sat=DATE(YEAR(B3)+1,MONTH(B3),DAY(B4))
     
Age Calculation   Q129277 XL: Undocumented Worksheet Function DATEDIF
Anniv/Birthdate06/01/1968Example 24990
Years of Age30  =DATEDIF(B9,NOW(),"Y")
+ Months2  =DATEDIF(B9,NOW(),"YM")
+ Days14  =DATEDIF(B9,NOW(),"MD")
Todays Date08/15/1998  =NOW()
Days after Last Birthdate75  =DATEDIF(B9,NOW(),"YD")
     
More Date Calculations    
  Day of Wk.Day of Wk. 
date chosen03/15/19992Mon36234
  =WEEKDAY(B18,1)  
   =B18 
First ddd of Month03/01/19992Mon=DATE(YEAR(B18),MONTH(B18),1)
Last ddd of Month03/31/19994Wed=DATE(YEAR($B$18),MONTH($B$18)+1,1)-1
First Sunday of Mo.03/07/19991Sun=DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(1+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)
First Monday03/01/19992Mon=DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(2+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)
First Tuesday03/02/19993Tue=DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(3+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)
First Wednesday03/03/19994Wed=DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(4+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)
First Thursday03/04/19995Thu=DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(5+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)
First Friday03/05/19996Fri=DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(6+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)
First Saturday03/06/19997Sat=DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(7+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)
Last Sunday of Mo.03/28/19991Sun=DATE(YEAR($B$18),MONTH($B$18)+1,1)- WEEKDAY(DATE(YEAR($B$18),MONTH($B$18)+1,7))
Last Monday03/29/19992Mon=DATE(YEAR($B$18),MONTH($B$18)+1,1)- WEEKDAY(DATE(YEAR($B$18),MONTH($B$18)+1,6))
Last Tuesday03/30/19993Tue=DATE(YEAR($B$18),MONTH($B$18)+1,1)- WEEKDAY(DATE(YEAR($B$18),MONTH($B$18)+1,5))
Last Wednesday03/31/19994Wed=DATE(YEAR($B$18),MONTH($B$18)+1,1)- WEEKDAY(DATE(YEAR($B$18),MONTH($B$18)+1,4))
Last Thursday03/25/19995Thu=DATE(YEAR($B$18),MONTH($B$18)+1,1)- WEEKDAY(DATE(YEAR($B$18),MONTH($B$18)+1,3))
Last Friday03/26/19996Fri=DATE(YEAR($B$18),MONTH($B$18)+1,1)- WEEKDAY(DATE(YEAR($B$18),MONTH($B$18)+1,2))
Last Saturday03/27/19997Sat=DATE(YEAR($B$18),MONTH($B$18)+1,1)- WEEKDAY(DATE(YEAR($B$18),MONTH($B$18)+1,8))
=offset(cellname,-1,0)27.03.19997Sat=OFFSET(B37,-1,0)
Last weeknum of yr53  =WEEKNUM(DATE(YEAR(B18),12,31),1)
This page was intended as a summary of calculations on my datetime page, but some of the formulas shown here differ, I think the nth weekday day of Month formulas are easier to follow at First, Last, Nearest, Closest, nth weekday (4th Monday) in Month, Date calculations on my Date and Time page.


First Wednesday (4=Wed) of the month during month of 03/03/1999
  =DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(4+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)
 add   7 to the above for the  2nd Wed
 add 14 to the above for the  3rd Wed
 add 21 to the above for the  4th Wed
 the 5th Wed add 28 if it is still in same month it is valid
   =IF(Month($B$18)<>Month(formula+28),"",formula+28)

=IF(Month($B$18)<>Month(DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(4+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)+28),"",DATE(YEAR($B$18),MONTH($B$18),1)+ MOD(4+7-WEEKDAY(DATE(YEAR($B$18),MONTH($B$18),1)),7)+28)

January, 2002 has a 5th Wednesday and it is January 30, 2002.  Except in a Leap Year, February does not have a 5th Wednesday or any other day of week in the month.

WORKDAY Worksheet Function

Formulas and Formats used to create table for the nth working day after the last day of previous month: 
Workday is an Analysis Toolpak addin, simply activate it under Tools.
=WORKDAY("10/01/2001"-1,ROW())     formatted as mm/dd/yyyy
=WORKDAY("11/01/2001"-1,ROW())
=WORKDAY("12/01/2001"-1,ROW())

=ROW()           formatted as General

=WEEKDAY(A1)     formatted as ddd
 ABCDEFGHIJK
110/01/20011Mon  11/01/20011Thu  12/03/20011Mon
210/02/20012Tue  11/02/20012Fri  12/04/20012Tue
310/03/20013Wed  11/05/20013Mon  12/05/20013Wed
410/04/20014Thu  11/06/20014Tue  12/06/20014Thu
510/05/20015Fri  11/07/20015Wed  12/07/20015Fri
610/08/20016Mon  11/08/20016Thu  12/10/20016Mon
710/09/20017Tue  11/09/20017Fri  12/11/20017Tue
810/10/20018Wed  11/12/20018Mon  12/12/20018Wed
910/11/20019Thu  11/13/20019Tue  12/13/20019Thu
1010/12/200110Fri  11/14/200110Wed  12/14/200110Fri
1110/15/200111Mon  11/15/200111Thu  12/17/200111Mon
1210/16/200112Tue  11/16/200112Fri  12/18/200112Tue
1310/17/200113Wed  11/19/200113Mon  12/19/200113Wed
1410/18/200114Thu  11/20/200114Tue  12/20/200114Thu
1510/19/200115Fri  11/21/200115Wed  12/21/200115Fri
1610/22/200116Mon  11/22/200116Thu  12/24/200116Mon
1710/23/200117Tue  11/23/200117Fri  12/25/200117Tue
1810/24/200118Wed  11/26/200118Mon  12/26/200118Wed
1910/25/200119Thu  11/27/200119Tue  12/27/200119Thu
2010/26/200120Fri  11/28/200120Wed  12/28/200120Fri
2110/29/200121Mon  11/29/200121Thu  12/31/200121Mon
2210/30/200122Tue  11/30/200122Fri  01/01/200222Tue
2310/31/200123Wed  12/03/200123Mon  01/02/200223Wed

The dates above were chosen to include a month that begins on a Saturday (Dec 1, 2001), which is not a workday. 

For illustrative purposes only.  Holidays were not included as a parameter in WORKDAY so Christmas (Dec 25), which is a US holiday is shown as a workday.
  to work with holidays use   =WORKDAY(start_date,days,holidays)
i.e. =WORKDAY("12/01/2001"-1,20,{"12/24/01","12/25/2001"})

Related

      See Related area on my Date and Time page.
You are one of many distinguished visitors who have visited my site here or in a previous location  since opening on Aug 15, 1998.

Formatting for most of this page was accomplished using:  Free Excel Downloads from Baarns Consulting -- (Rob Bovey) Microsoft Office Resource Center.  Of particular interest is the Excel to Web Table Converter (XL5 and up) which will convert selected cells to HTML and can include borders for empty cells.  Includes source code.  XL97 users especially will appreciate this one since MS dropped option choices in its converter (Save As).    If done today would use my own XL2HTML or to show row and column headers with the XL2HTMLx conversion.

Return to David McRitchie's Excel Page. Return to Date & Time Page.  [Site Search -- Excel] 

Updated on: 8/15/1998, 09/04/2002.

For comments or feedback contact:  David McRitchie.

E-Mail Address: DMcRitchie@msn.com