Returns the UNIX timestamp in milliseconds for a date and time, or parsed from a date string.
timestamp builds a time value you can compare with time. Pass the parts, timestamp(2024, 3, 15, 9, 30, 0), or a date string, timestamp("2024-03-15T09:30:00Z"). The parts are read in the exchange time zone unless the first argument names another one.
Overloads with a timezone argument put it first: timestamp("America/New_York", 2024, 3, 15, 9, 30, 0). Hour, minute and second default to 0.
Syntax
timestamp(dateString: const string) -> const int
timestamp(dateString: series string) -> series int
timestamp(year: simple int, month: simple int, day: simple int, hour: simple int (optional), minute: simple int (optional), second: simple int (optional)) -> simple int
timestamp(year: series int, month: series int, day: series int, hour: series int (optional), minute: series int (optional), second: series int (optional)) -> series int
timestamp(timezone: simple string, year: simple int, month: simple int, day: simple int, hour: simple int (optional), minute: simple int (optional), second: simple int (optional)) -> simple int
timestamp(timezone: series string, year: series int, month: series int, day: series int, hour: series int (optional), minute: series int (optional), second: series int (optional)) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| dateString | const/ | required | The date as text, in ISO 8601 form or as "15 Mar 2024 09:30 +0000". Put an offset in the text so the result does not depend on a default. |
| year | simple/ | required | The calendar year, such as 2024. |
| month | simple/ | required | The month of the year, from 1 for January to 12 for December. |
| day | simple/ | required | The day of the month, 1 to 31. |
| hour | simple/ | 0 | The hour on a 24-hour clock, from 0 to 23. |
| minute | simple/ | 0 | The minute within the hour, from 0 to 59. |
| second | simple/ | 0 | The second within the minute, from 0 to 59. |
| timezone | simple/ | required | The IANA time zone name or UTC offset the other arguments are read in, such as "UTC" or "America/New_York". |
Returns
const/simple/series int: The number of milliseconds since 1970-01-01 00:00 UTC for the given moment.
Remarks
- The result has the strongest qualifier of its arguments, so a date written into the script as literals stays a constant.
- A date string accepts ISO 8601 ("2024-03-15T09:30:00Z", "2024-03-15T09:30:00+02:00") and the form "15 Mar 2024 09:30 +0000".
- A date with a missing year, month or day returns na.
- On Sidechair: pass hour, minute and second explicitly in the part forms, as in timestamp(2024, 3, 15, 0, 0, 0). The shorter forms that leave them out stop the script, or return na when a timezone is given, instead of defaulting to 0. The date-string forms work as written.
Example
//@version=6
indicator("After a start date", overlay = true)
start = timestamp("America/New_York", 2024, 1, 2, 9, 30, 0)
active = time >= start
bgcolor(active ? color.new(color.green, 92) : na)
plot(active ? close : na, "Close", color.green)See also
Runs on Sidechair