About date formulas
Date functions are useful when you want to compare data collected between two date periods. Date formulas allow you to apply date related functions to your formulas.
Date formulas
The date formulas include:
Function | Description | Examples |
---|---|---|
|
Returns the result of adding the specified number of days to the given date. |
|
|
Returns the result of adding the specified number of minutes to the given date/datetime/time. |
|
|
Returns the result of adding the specified number of months to the given date. |
|
|
Returns the result of adding the specified number of seconds to the given date/ datetime/ time. |
|
|
Returns the result of adding the specified number of weeks to the given date. |
|
|
Returns the result of adding the specified number of years to the given date. |
|
|
Returns the date portion of a given date. |
|
|
Returns the number (1-31) of the day of the month for the given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, the 15th of the month is the start of the fiscal month.
|
|
Returns the number of the day in a quarter for a given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year.
|
|
Returns the number (1-7) of the day in a week for a given date. Monday is 1, and Sunday is 7. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, Wednesday is the start of the fiscal week.
|
|
Returns the number (1-366) of the day in a year from a given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year.
|
|
Returns the day of the week for the given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, the days of the week are in French in the fiscal calendar.
|
|
Subtracts the second date from the first date and returns the result in number of days. |
|
|
Subtracts the hour of the second date from the hour of the first date and returns the result in number of hours. |
|
|
Subtracts the minute of the second date from the minute of the first date and returns the result in number of minutes. |
|
|
Subtracts the month of the second date from the month of the first date and returns the result in number of months. The optional third parameter specifies the custom calendar the formula uses to calculate the result. |
|
|
Subtracts the quarter of the second date from the quarter of the first date and returns the result in number of quarters. The optional third parameter specifies the custom calendar the formula uses to calculate the result. |
|
|
Subtracts the second date from the first date and returns the result in number of seconds. |
|
|
Subtracts the week of the second date from the week of the first date and returns the result in number of weeks. The optional third parameter specifies the custom calendar the formula uses to calculate the result. |
|
|
Subtracts the year of the second date from the year of the first date and returns the result in number of years. The optional third parameter specifies the custom calendar the formula uses to calculate the result. |
|
|
Returns the hour of the day for the given date. |
|
|
Returns true if the given date falls on a Saturday or Sunday. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, Wednesday and Thursday are the days of the weekend in the fiscal week.
|
|
Returns the month from the given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, the months of the year are in Spanish in the fiscal calendar.
|
|
Returns the number (1-12) of the month from a given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year.
|
|
Returns the month (1-3) number for the given date in a quarter. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year.
|
|
Returns the current date and time in your locale’s standard date and time format. For example, if your locale is English (United States), it returns |
|
|
Returns the number (1-4) of the quarter associated with the given date. You can add an optional second parameter to specify fiscal or calendar dates. The default is calendar. |
In the following example, May 1st is the start of the fiscal year.
|
|
Returns |
In the following example, the 15th is the start of the fiscal month.
|
|
Returns the date for the first day of the quarter for the given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year.
|
|
Returns the date for the first day of the week for the given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, Wednesday is the start of the fiscal week.
|
|
Returns the date for the first day of the year for the given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year.
|
|
Returns the time to the closest hour. |
|
|
Returns the time to the closest minute. |
|
|
Returns the time portion of a given date. |
|
|
Returns the current date in your locale’s standard date format. For example, if your locale is English (United States), it returns |
|
|
Returns the week number for the given date in a month. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, the 15th is the start of the fiscal month.
|
|
Returns the week number for the given date in a quarter. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year.
|
|
Returns the week number for the given date in a year. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year.
|
|
Returns the year in integer format for a given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year. Per standard convention, the fiscal year is defined by the year-end date.
|
|
Returns the year in string format for a given date. You can add an optional second parameter to specify whether a fiscal or calendar year is used to calculate the result. The default is calendar. |
In the following example, May 1st is the start of the fiscal year. Per standard convention, the fiscal year is defined by the year-end date.
|
Calculate date formulas
Calculating date formulas is useful when you want to compare data from different date periods. Here are some examples of using date formulas:
Example 1
The following example shows you how to create formulas that you can use to compare data from this week to last week.
-
The formula for this week is:
week ( today () ) - week (date)
-
The formula for last week is:
diff_days ( week ( today () ) ) , week ( date ) )
Example 2
The following example shows you how to calculate the percent increase from the last date period to this period in terms of revenue.
-
Create the formula:
this week revenue = sum ( if ( this week ) then revenue else 0 )
-
Then create the formula:
last week revenue = sum ( if (last week ) then revenue else 0 )
-
Use nested formulas to calculate the percent increase by creating a parent formula:
percent increase = ( ( this week revenue - last week revenue) / last week revenue ) * 100
Fiscal and Gregorian calendars
For the following date formulas, you can further specify either fiscal
, Gregorian calendar
, or any other custom calendar on which to base date calculations.
(If you do not specify a calendar type, the formula defaults to the default cluster calendar.)
-
day
-
day_number_of_quarter
-
day_number_of_week
-
day_number_of_year
-
day_of_week
-
diff_months
-
diff_quarters
-
diff_weeks
-
diff_years
-
is_weekend
-
month
-
month_number
-
month_number_of_quarter
-
quarter_number
-
start_of_month
-
start_of_quarter
-
start_of_week
-
start_of_year
-
week_number_of_month
-
week_number_of_quarter
-
week_number_of_year
-
year
Your ThoughtSpot administrator and ThoughtSpot Support can create a custom calendar to start on any month.
If the fiscal
year is not explicitly configured in the system, fiscal
defaults to January, the same as the Gregorian calendar
.
For example, the formula month_number_of_quarter (05/31/2014)
would return 2
based on the default Gregorian calendar, whereas the formula month_number_of_quarter (05/31/2014, 'fiscal')
would return 1
if your administrator has configured the fiscal calendar to start in May.
Related information