Skip to content

dayofweek() - PineScript Function

Calculates the day number of the week, in a specified time zone, from a UNIX timestamp.

dayofweek(time, timezone) → series int
NameTypeDescription
timeseries intUNIX timestamp (ms) to evaluate.
timezoneconst stringOptional IANA timezone. Defaults to the exchange timezone.

The calculated day number, expressed in the specified time zone.

  • Day numbers follow TradingView’s enum constants (dayofweek.monday, …, dayofweek.sunday).
  • Pass syminfo.timezone to align with the instrument’s exchange.
//@version=5
indicator("Weekday shading", overlay=true)
dow = dayofweek(time, syminfo.timezone)
isWeekend = dow == dayofweek.saturday or dow == dayofweek.sunday
bgcolor(isWeekend ? color.new(color.gray, 90) : na)
plot(close, "Close")