Extract weekday, hour or week number from a date column

Updated

Extract from date/time takes one part of every date in a date column and puts it in a new column: the year, quarter, month, day of the month, day of the week, ISO week number, hour, minute or second, or the date with its time removed. A timestamp on its own is hard to group; its hour or weekday is easy. This is how you ask questions such as "do defects cluster on Mondays?" or "are night-shift stops longer?".

When to use it

  • You have timestamps of events (stops, alarms, defects, complaints) and want to see whether they depend on the hour, the weekday or the week.
  • You want daily, weekly or monthly groups for a report, such as defects per ISO week.
  • Readings were logged with a time and you need to group them by day, for example to compare days on a time series plot.
  • You want a shift or a season, which you can build by extracting the hour or month and then recoding it.

How to do it in StatLab

  1. Select a cell in the date column and choose Data › Extract from date/time…. Only date columns (labels ending in -D) are offered; if a column of dates shows -T, convert it first with Change data type.
  2. Choose the Column.
  3. Under Extract, choose the part:
    • Year, Quarter (1 to 4), Month (1 to 12), Day of the month;
    • Day of the week (Monday = 1), from 1 for Monday to 7 for Sunday;
    • Week of the year (ISO): weeks start on Monday, and week 1 is the week that holds the year's first Thursday;
    • Hour (0 to 23), Minute, Second;
    • Date without the time, which gives a date column instead of numbers.
  4. Press OK. The new column goes after the last column in use, named after the original and the part, such as Stop_hour. Ctrl+Z undoes it.

Missing dates give missing values in the new column.

Example

A packaging line records every unplanned stop with its start time and its length in minutes. The maintenance lead suspects nights are worse but has no numbers. Ten stops over ten days:

C1-D StopC2 Minutes
2026-11-23 06:4012
2026-11-23 22:1535
2026-11-24 14:058
2026-11-26 23:5041
2026-11-27 03:2018
2026-11-28 07:309
2026-11-30 05:5527
2026-11-30 22:4033
2026-12-01 15:106
2026-12-02 01:2522

(Dates are written here as year-month-day; the worksheet shows them in your region's order.)

She extracts three parts, one at a time: Hour, Day of the week (Monday = 1) and Date without the time. Results for the first: Extracted hour from C1-D Stop into C3.

C3 Stop_hourC4 Stop_weekdayC5-D Stop_date
612026-11-23
2212026-11-23
1422026-11-24
2342026-11-26
352026-11-27
762026-11-28
512026-11-30
2212026-11-30
1522026-12-01
132026-12-02

The plant runs three shifts: 06:00 to 14:00, 14:00 to 22:00 and 22:00 to 06:00. She recodes Stop_hour into a shift column with the rules 6:13 → Morning, 14:21 → Afternoon, 22:23 → Night and 0:5 → Night. Adding up the minutes for each shift:

ShiftStopsMinutes
Morning221
Afternoon214
Night6176
Unplanned downtime by shift050100150Minutes of downtimeMorningAfternoonNight
Unplanned downtime by shift

The night shift has six of the ten stops and 176 of the 211 minutes, 83% of the downtime. Ten stops are not proof, but they turn a hunch into a specific question for maintenance: what is different at night (staffing, temperature, material from the evening delivery)?

How to read the results

  • Weekday 1 is Monday and 7 is Sunday. Four of the ten stops started on a Monday, but the ten days include two Mondays, two Tuesdays and two Wednesdays and only one of each other day, so compare stops per day, not raw counts.
  • Hour is the clock hour, 0 to 23. A stop at 23:50 has hour 23, and one at 01:25 has hour 1.
  • Date without the time is still a date column (C5-D), ready to group readings by day.

Common mistakes

  • Splitting night shifts at midnight. Grouping by Date without the time puts the stop at 03:20 on 27 November in a different day from the one at 23:50 on 26 November, though both belong to the same night shift. Group by shift, or shift the times back by six hours with the calculator (Stop - 0.25, since a quarter of a day is six hours) before extracting the date.
  • Mixing ISO weeks with calendar years. 1 January 2027 is in ISO week 53, which belongs to 2026, while Year gives 2027. Near New Year, label weeks with care, or group by Date without the time instead.
  • Comparing raw counts across unequal periods. If your data covers two Mondays and one Tuesday, Mondays will look worse. Divide by the number of days of each kind.
  • Extracting from a text column. Dates stored as text cannot be extracted from. Convert the column to dates first.

Frequently asked questions

Why does Monday come out as 1?

StatLab numbers weekdays the ISO way: Monday 1 to Sunday 7. The WEEKDAY function in the calculator uses the same numbering.

What is an ISO week?

A week from Monday to Sunday. Week 1 of a year is the week that contains its first Thursday, so a few days at the start of January can belong to week 52 or 53 of the previous year, and a few at the end of December to week 1 of the next.

Can I get the month name instead of a number?

Extract Month and then recode 1 to 12 into names with Recode values.

Does extracting change the original date column?

No. The part goes into a new column; the original stays as it was.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab