Excel For Analysts Date Time Functions
Excel For Analysts Date Time Functions
Every date in Excel has an associated date value, which is how Excel
calculates the passage of time (using midnight on 1/1/1900 as the starting point)
Excel recognizes most typed dates and automatically applies a common format
(i.e. m/d/yyyy), along with an associated date value (cell format General)
Note: If you type a date in a format that Excel does NOT recognize, it will be treated as text and
there will be no associated date value; however, you can use a DATEVALUE or TIMEVALUE
function to convert unformatted dates or times into serial values
Jan 1,1900 is the first date with an assigned date value (1). Feb 6,
2015 is the 42,041st day since 1/1/1900, so its date value = 42041
49
Date Formatting
To format dates in Excel, you can either select a preset option from the “Date”
category of the “Format Cells” dialog box, OR create your own custom format
Preset Formats: Custom Format: You can build your own custom
formats using combinations of
date/time codes. For example:
50
Fill Series
When you drag the corner of a cell containing a date, Excel automatically
applies subsequent values automatically using Fill Series options:
Fill Weekdays = Increases the date by 1 day per cell (excluding weekends)
51
TODAY()/NOW()
The TODAY() and NOW() functions return the current date or exact time
Note: These are volatile functions, meaning that they change with every worksheet calculation
PRO TIP:
Make sure to enter TODAY() and NOW() functions with both
parentheses included – these functions don’t refer to other cells
52
Serialization Formulas
Excel will always calculate dates and times based on their precise underlying
serial values, but what if you need to work with less-specific values, like
months instead of days, or hours instead of seconds?
The YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND functions extract
individual components of a given date:
53
EOMONTH
Use the EOMONTH function to calculate the last day of a given month, or to
calculate the start/end dates of previous or future months
=EOMONTH(start_date, months)
Reference to the cell containing Number of months before or after the start/current date (positive number
the start/current date yields a date in the future, negative number yields a date in the past
=EOMONTH(C2, 0)
=EOMONTH(C2, -1)+1
=EOMONTH(C2, 0)+1
54
YEARFRAC
YEARFRAC calculates the fraction of a year represented by the number of whole days
between two dates
55
WEEKDAY
If you want to know which day of the week a given date falls on, there are two
ways to do it:
1) Use a custom cell format of either “ddd” (Sat) or “dddd” (Saturday)
-Note that this doesn’t change the underlying value, only how that value is displayed
2) Use the WEEKDAY function to return a serial value corresponding to a particular
day of the week (either 1-7 or 0-6)
56
WORKDAY/NETWORKDAYS
WORKDAY returns a date that is a specified number of days before or after a given start
date, excluding weekends and (optionally) holidays; NETWORKDAYS counts the
number of workdays between two dates:
57
DATEDIF
DATEDIF calculates the number of days, months, or years between two dates
Reference to the cell Reference to the cell How do you want to calculate the difference?
containing the start date containing the end date
“D” = # of days between dates
“M” = # of months between dates
“Y” = # of years between dates
“MD” = # of days between dates, ignoring months and years
PRO TIP:
If you only need to calculate the # of days between dates, just use subtraction
58