Date Extraction Functions
These functions calculate or round-down timestamp values to the nearest specified time period, such as hour, day, week, month, and quarter.
You can use the calculated timestamps to aggregate data using a different grain. For example, you might apply the EXTRACTDAY() function to sales order dates to calculate a timestamp for midnight on the day that orders occur, so that you can aggregate the data by day.
| Function | Example | Description | Syntax |
|---|---|---|---|
|
Extract Day |
EXTRACTDAY("Order Date")
|
Returns a timestamp for midnight (12 AM) on the day in which the input value occurs. For example, if the input timestamp is for 3:02:01 AM on February 22nd, the function returns the timestamp for 12:00:00 AM on February 22nd. |
|
|
Extract Hour |
EXTRACTHOUR("Order Date")
|
Returns a timestamp for the start of the hour in which the input value occurs. For example, if the input timestamp is for 11:18:30 PM, the function returns the timestamp for 11:00:00 PM. |
|
|
Extract Hour of Day |
EXTRACTHOUROFDAY("Order Date")
|
Returns a timestamp where the hour equals the hour of the input value with default values for year, month, day, minutes, and seconds. |
|
|
Extract Millisecond |
EXTRACTMILLISECOND("Order Date")
|
Returns a timestamp containing milliseconds for the input value. For example, if the input timestamp is for 15:32:02.150, the function returns the timestamp for 15:32:02.150. |
|
|
Extract Minute |
EXTRACTMINUTE("Order Date")
|
Returns a timestamp for the start of the minute in which the input value occurs. For example, if the input timestamp is for 11:38:21 AM, the function returns the timestamp for 11:38:00 AM. |
|
|
Extract Month |
EXTRACTMONTH("Order Date")
|
Returns a timestamp for the first day in the month in which the input value occurs. For example, if the input timestamp is for February 22nd, the function returns the timestamp for February 1st. |
|
|
Extract Quarter |
EXTRACTQUARTER("Order Date")
|
Returns a timestamp for the first day in the quarter in which the input value occurs. For example, if the input timestamp occurs in the third fiscal quarter, the function returns the timestamp for July 1st. |
|
|
Extract Second |
EXTRACTSECOND("Order Date")
|
Returns a timestamp for the input value. For example, if the input timestamp is for 15:32:02.150, the function returns the timestamp for 15:32:02. |
|
|
Extract Week |
EXTRACTWEEK("Order Date")
|
Returns the date of the first day of the week (Sunday) in which the input value occurs. For example, if the input timestamp is for Wednesday, September 24th, the function returns the timestamp for Sunday, September 21st. Note: If the first day of a week (i.e. Sunday) falls in a previous year and would therefore adversely affect the aggregation, the function returns the 7th day of the week (i.e. Saturday) in the current year instead of the first day of the week in the previous year. For example, 1/1/24, 1/2/24, and 1/3/24 all aggregate to Saturday 1/6/24, rather than Sunday 12/29/23. |
|
|
Extract Year |
EXTRACTYEAR("Order Date")
|
Returns a timestamp for January 1st for the year in which the input value occurs. For example, if the input timestamp occurs in 1967, the function returns the timestamp for January 1st, 1967. |
|