dayofweek() - PineScript Function
dayofweek()
Section titled “dayofweek()”Overview
Section titled “Overview”Calculates the day number of the week, in a specified time zone, from a UNIX timestamp.
Syntax
Section titled “Syntax”dayofweek(time, timezone) → series intParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
time | series int | UNIX timestamp (ms) to evaluate. |
timezone | const string | Optional IANA timezone. Defaults to the exchange timezone. |
Returns
Section titled “Returns”The calculated day number, expressed in the specified time zone.
Remarks
Section titled “Remarks”- Day numbers follow TradingView’s enum constants (
dayofweek.monday, …,dayofweek.sunday). - Pass
syminfo.timezoneto align with the instrument’s exchange.
Examples
Section titled “Examples”//@version=5indicator("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")