Sub topic 4
Pulling Out Year, Month, Day, Hour, Minute and Second
Assume you can enter formulas, use relative and absolute cell references, and apply number formats from the Format menu. This chapter uses date-time values in column A, beginning in A2.
A date-time value contains both a calendar date and a time of day. Google Sheets stores the date as a whole-number day count and the time as a fraction of a day. Functions such as YEAR and HOUR read those stored values and return one part.
Extracting calendar parts
Use these functions to retrieve parts of a date:
| Function | Returns | Example result for `2026-11-28 14:35:42` |
|---|---|---|
| `YEAR` | Four-digit year | `2026` |
| `MONTH` | Month number from 1 to 12 | `11` |
| `DAY` | Day of the month from 1 to 31 | `28` |
Enter these formulas in separate cells:
=YEAR(A2)
=MONTH(A2)
=DAY(A2)These results are numbers, so you can use them in other formulas. For example, this formula returns the first day of the same month:
=DATE(YEAR(A2), MONTH(A2), 1)The formula extracts the year and month from A2, then combines them with day 1.
Extracting time parts
Use these functions for the time portion:
=HOUR(A2)
=MINUTE(A2)
=SECOND(A2)For 2026-11-28 14:35:42, they return 14, 35, and 42.
If a result looks unexpected, check whether A2 contains a real date-time value. A cell may display a date while storing text. The functions may then return an error or fail to interpret the value correctly.
How the extraction works
A date-time is one numeric value. The whole-number portion represents days, and the fractional portion represents the time within a day.
flowchart TD
A["Date-time value in A2"] --> B["YEAR, MONTH, DAY"]
A --> C["HOUR, MINUTE, SECOND"]
B --> D["Calendar calculations"]
C --> E["Time-based calculations"]The displayed format does not determine what these functions extract. For example, a cell formatted to show only November 2026 can still contain a specific day and time.
Combining extracted parts
You can combine parts to create labels or grouping keys. This formula creates a year-month key:
=TEXT(A2, "yyyy-mm")You can also test a part directly. This formula checks whether a date falls in December:
=MONTH(A2)=12For weekday numbers, use WEEKDAY. With type 2, Monday is 1 and Sunday is 7:
=WEEKDAY(A2, 2)This is useful when you need to identify weekends or group records by weekday.
Exercise
If A2 contains 2025-03-09 07:04:12, what do =YEAR(A2), =MONTH(A2), =DAY(A2), and =HOUR(A2) return?
Show answer
They return 2025, 3, 9, and 7.