Sidechair

timestamp()

Browse the reference

Returns the UNIX timestamp in milliseconds for a date and time, or parsed from a date string.

Try it in the editor

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

Pine Script
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 int

Arguments

NameTypeDefaultDescription
dateStringconst/series stringrequiredThe 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.
yearsimple/series intrequiredThe calendar year, such as 2024.
monthsimple/series intrequiredThe month of the year, from 1 for January to 12 for December.
daysimple/series intrequiredThe day of the month, 1 to 31.
hoursimple/series int0The hour on a 24-hour clock, from 0 to 23.
minutesimple/series int0The minute within the hour, from 0 to 59.
secondsimple/series int0The second within the minute, from 0 to 59.
timezonesimple/series stringrequiredThe 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

Pine ScriptTrade only after a dateOpen in editor
//@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