Excel Date/Time Functions
Excel offers these date and time functions.
Contents
Construction
A date is constructed with the DATE function, taking (in order) a numeric year, month, and date.
A time is constructed with the TIME function, taking (in order) numeric hours, minutes, and seconds.
A common pattern to guard against over-specified dates is to extract the necessary components from a date/time and construct the minimal value.
=DATE(YEAR(B4), MONTH(B4), DAY(B4))
This would convert 1/1/2020 12:30:00 PM (which cannot be logically compared to a date) into 1/1/2020 (which can).
DATEVALUE and TIMEVALUE
Excel tries to convert strings that look like dates/times when they are entered. This functionality is exposed in the DATEVALUE and TIMEVALUE functions.
TODAY and NOW
TODAY exposes the current system date and NOW exposes the current system datetime.
Extraction
Given a date or time, to extract a component of it, try one of the YEAR, MONTH, DAY, HOUR, MINUTE, or SECOND functions.
Durations
DATEDIF
TODO: code example
DAYS
TODO: code example