> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Sessions and intervals

> Bar times and their parts, building a time with timestamp, testing a trading session, and reading the chart's interval.

Times are integers in milliseconds since the Unix epoch.

| Name | Value |
| - | - |
| `time` | Opening time of the bar. |
| `time_close` | Closing time: opening time plus one interval. |
| `time_sessionday` | The trading day of the bar. |
| `last_bar_time` | Opening time of the chart's last bar. |
| `timenow` | The wall clock when the script ran, not a bar time. |

There is no `time.now()` and no `timeframe` namespace (`timeframe.period` fails with No variable with name `timeframe` found): use `interval.interval`.

## Parts of a time

`year`, `month`, `dayofmonth`, `dayofweek`, `hour`, `minute`, `second` are series ints for the current bar. Each is also a function of a time and an optional zone: `hour(time, "America/New_York")`. The zone is an IANA name; the default is the exchange's (`syminfo.timezone`). A name it cannot load, `"UTC-5"` included, gives 0. `weekofyear(time)` exists only as a function. `dayofweek` counts Sunday as 1 to Saturday as 7; compare with `dayofweek.sunday` ... `dayofweek.saturday`.

`timestamp(2024, 3, 1)` builds a time (hour, minute, second optional; the exchange's zone), `timestamp("UTC", 2024, 3, 1, 9, 30, 0)` names the zone (an IANA name, or an offset such as `"UTC-5"` or `"GMT+0530"`, as in `time` and `str.format_time`), and `timestamp("2024-03-01")` reads a date string (UTC without a zone; `na` if unreadable). When the script is added to the chart `timestamp()` is `na`, so it cannot be the default of `input.time`; give milliseconds.

## Testing a session

`time(interval, session)` returns the opening time of the `interval` period that holds the bar, or `na` when that opening time is outside `session`. Periods are cut on the clock (a 1-hour period holding a 09:30 bar opens at 09:00), so `time("1D", "0930-1600")` is always `na`. A session is `"0930-1600"`, with ranges joined by commas (`"1000-1100,1400-1500"`) and optionally `:` and days, Sunday as 1 (`"0930-1600:23456"`). A range that ends before it starts wraps past midnight; `"0000-0000"` is the whole day. Times are read in the exchange's zone; a `timezone` argument between `session` and `bars_back` changes that. `time_close` takes the same arguments.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Volume in the window today")
inWindow = not na(time(interval.interval, "0930-1600"))
static float total = 0.0
if interval.change("1D") {
    total := 0.0
}
if inWindow {
    total += volume
}
plot(total, title="Window volume")
```

`session.isfirst` is true on a session's first bar; `session.date` is its date string. There is no `session.islast`: Namespace `session` has no variable `islast`. Did you mean `isfirst`?

## The chart's interval

An interval string is a number and a unit: `s`, `m`, `h`, `D`, `W`, `M` (`"30s"`, `"5m"`, `"1h"`, `"1D"`).

* `interval.interval` is the chart's interval string, `interval.multiplier` its number, `interval.timeframe_minutes` its length in minutes.
* `interval.isintraday`, `isseconds`, `isminutes`, `ishourly`, `isdaily`, `isweekly`, `ismonthly`, `iseod` are simple bools.
* `interval.change("1D")` is true on the first bar of each new day (or other period).
* `interval.in_seconds("1D")` is 86400 (no argument: the chart's interval); `interval.from_seconds(86400)` is `"1D"`. A month is 2628003 seconds; tick and range intervals give `na`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.