get_year_from_timestamp()

Returns the year value of a given timestamp.

Synopsis

get_year_from_timestamp(timestamp)

Description

This function extracts and returns the year defined by a given timestamp. The timestamp must be formatted as either YYYYMMDDHH or YYYYMMDD, where YYYY is a four-digit year, MM is a two-digit month, DD is a two-digit day, and HH is a two-digit hour.

Parameters

<timestamp>

An expression representing a timestamp, formatted as either YYYYMMDDHH or YYYYMMDD.

Returns

The year value (an integer) of the given timestamp.

Examples

The following returns \(2021\) since this timestamp represents January 2, 2021 at 12 noon.

get_year_from_timestamp(2021010212)

Errors

A timestamp that exceeds the 10-character format will evaluate the final 10 digits as a timestamp. That is, get_year_from_timestamp(20205069787654321) returns \(9787\).

A malformed timestamp that does not represent an actual date will not raise an error.

See Also

get_day_from_timestamp(), get_hour_from_timestamp(), get_month_from_timestamp(), get_year_from_timestamp()