Calendar features

Also known as: date features

On this page 7

Calendar features, also called date features, are model inputs derived from the timestamp of each observation, such as day of week, month, hour of day, holiday flags or the number of days to a known event. In Time series & forecasting, a core area of artificial intelligence, they let a model learn recurring patterns tied to the calendar instead of inferring them only from past values of the target.

Unlike lag features, calendar features are known in advance for every future date. That property makes them among the most reliable covariates in multi-step forecasting: a model can use the fact that next Tuesday is a public holiday without having to predict anything about the holiday itself.

How calendar features encode time

Calendar features work by turning a single timestamp into several descriptive variables that a model can relate to the target. A raw date such as 2026-12-24 18:00 carries little usable signal to most learners, but its components reveal position in the daily, weekly and yearly cycles and its relation to special days.

Each extracted component targets a different seasonal period. Hour of day captures intraday cycles in electricity load or web traffic, day of week captures weekly shopping rhythms, and month or week of year captures annual seasonality such as heating demand. Event-based features capture effects that do not repeat at a fixed period, such as Easter or a regional school holiday.

FeatureTypical valuesPattern captured
Hour of day0 to 23Intraday demand cycles
Day of week1 to 7Weekday versus weekend behavior
Day of month1 to 31Payday and billing effects
Week of year1 to 53Annual seasonality at weekly resolution
Month or quarter1 to 12 or 1 to 4Broad seasonal shifts
Holiday flag0 or 1, or holiday nameIrregular event effects
Days to or from eventInteger, often cappedBuild-up and aftermath of events
Common calendar features and the patterns they capture

Encoding choices for cyclical and categorical dates

The encoding of a calendar feature matters as much as the choice of feature. A plain integer for month tells a linear model that December is twelve times January and hides the fact that December is adjacent to January in the yearly cycle.

EncodingHow it worksBest suited to
Integer or ordinalComponent stored as a numberTree ensembles such as gradient boosting
One-hot encodingOne binary column per categoryLinear models with few categories
Sine and cosine pairMaps a cycle onto a circleNeural networks and linear models
Fourier termsSeveral harmonics of a long periodSmooth annual seasonality
Learned embeddingDense vector trained with the modelDeep forecasters with many series
Encoding options for calendar features

The sine and cosine transformation computes sin(2πx/P) and cos(2πx/P) for a component x with period P, so hour 23 and hour 0 end up close together. For long periods such as 365.25 days, a few Fourier harmonics describe a smooth seasonal shape with far fewer parameters than 52 weekly indicator columns. Gradient-boosted trees usually handle plain integers well, because splits can isolate any range.

Holidays and special events

Holiday features are usually the most valuable and most error-prone calendar inputs. Fixed-date holidays are easy, but moving holidays such as Easter, Ramadan or Chinese New Year shift across Gregorian dates, and regional calendars differ between countries, states and even school districts.

  • Bridge days between a holiday and a weekend often behave like partial holidays.
  • Lead and lag windows capture shopping before Christmas or recovery after a long weekend.
  • Holiday type matters: a retail peak and an office closure move demand in opposite directions.
  • Observed dates apply when a holiday falls on a weekend and is moved to a weekday.

Forecasting tools such as Prophet expose holiday windows directly, while global models like the Temporal Fusion Transformer accept holiday indicators as known future covariates. In every case the holiday table must be maintained for the entire forecast horizon.

Calendar features are one of several families of temporal inputs, and strong models usually combine them. The key distinction is whether the value is known at prediction time for every step of the horizon.

Input typeKnown for future stepsMain role
Calendar featuresYes, deterministicFixed cycles and events
Lag featuresOnly up to the lag lengthShort-term dependence on past values
Rolling window featuresOnly from past dataRecent level and volatility
Fourier termsYes, deterministicSmooth periodic shape
Exogenous covariatesSometimes, often forecastExternal drivers such as price or weather
Calendar features versus other temporal inputs

Classical methods handle seasonality differently. ARIMA and ETS models capture regular seasonal periods through seasonal differencing or seasonal states, while STL decomposition separates them before modeling. Calendar features are the natural choice for machine learning regressors that treat forecasting as supervised learning.

Pitfalls and good practice

Most problems with calendar features come from time zones, alignment and redundancy rather than from the features themselves. A careful pipeline derives every component from the local time of the process being modeled.

  • UTC timestamps shift the apparent hour and even the day for local behavior; convert to local time first.
  • Daylight saving transitions create 23-hour and 25-hour days that distort hourly features.
  • Too many sparse indicators let the model memorize noise when history covers only one or two years.
  • Missing future holidays in the lookup table silently degrade forecasts at the horizon end.
  • Redundant seasonal terms alongside a seasonal model can double-count the same pattern.

Feature value should be verified with time series cross-validation that respects temporal order, comparing error metrics such as MASE with and without each feature group. Errors concentrated around holidays often signal a missing or misaligned event feature.

Stripped to the essentials

Many things repeat on a calendar. Shops are busier on Saturdays. Homes use more power on winter evenings. Traffic drops on public holidays.

Calendar features tell a forecasting model where a date sits in these cycles. Instead of a bare date, the model sees that the day is a Friday, in December, two days before a holiday.

The big advantage is that the calendar is known in advance. Nobody knows next month’s sales, but everybody knows which days will be weekends.

Where it is applied

A grid operator forecasts hourly electricity load 48 hours ahead for a region with about two million customers. The team uses a gradient-boosted tree model with lag features of the last week of load and a weather forecast as exogenous inputs.

Errors are largest on Mondays, during daylight saving changes and around public holidays. The analysts add local hour of day, day of week, a holiday flag, a bridge-day flag and a school vacation indicator, all derived in local time from a maintained regional calendar.

Evaluated with rolling-origin cross-validation over two years, mean absolute percentage error falls from about 4.1 to about 3.0 percent. The largest gains occur on holidays, where the previous model had overestimated load by more than 10 percent because it treated those days as ordinary weekdays.