Extract time period from a date: year, month, dayofmonth, dayofyear
Syntax
{year | month | dayofmonth | dayofyear}¹ ( op )
Input parameters
op |
the input date/time period |
Examples of valid syntaxes
year (2022Q1)
dayofyear (2020-12-14)
ds2 := ds1[calc Me2 := dayofmonth(Me1)]
Semantics for scalar operations
The operator year returns the year of the given date/time period. The operator month returns the month of the given date/time period (between 1 and 12). The operator dayofmonth returns the ordinal day within the month (between 1 and 31). The operator dayofyear returns the ordinal day within the year (between 1 and 366).
Input parameters type
op:
component<time>
| time
Result type
result
component<integer>
| integer
Additional Constraints
None.
Behaviour
The scalar version of this operators takes as input one date or time_period value and returns a integer value corresponding to the specified time period.
In the component version, that can be used in a calc clause, a new component of type integer is added to the dataset.
Examples
Given the dataset DS_1:
Input DS_1 (see structure)
Id_1 |
Me_1 |
---|---|
G |
2019-01-01 |
H |
2019-07-01 |
T |
2020-12-31 |
Example 1
DS_r:= DS_1[calc Me2 := month(Me_1, 2, "M")];
results in (see structure):
Id_1 |
Me_1 |
Me_2 |
---|---|---|
G |
2019-01-01 |
1 |
G |
2019-07-01 |
7 |
T |
2020-12-31 |
12 |
Example 2
datediff (2021Q2, 2021-11-04);
returns 127.