/    /  Amazon QuickSight – dateDiff

Amazon QuickSight – dateDiff

 

The dateDiff function in QuickSight is used to calculate the difference between two dates. The function takes two required arguments, which are the two dates you want to compare, and an optional third argument specifying the unit of time in which you want to express the difference.

Syntax

#Start#
dateDiff(date1, date2, [period])
#End#

 

This function takes three arguments

 

  • date1 and date2: parameters are the two dates you want to compare. These can be specified as dates, date literals, or date fields from your data source.
  • Period: parameter is an optional string that specifies the unit of time in which you want to express the difference between the two dates. If this parameter is not specified, the function returns the difference between the two dates in days.

 

The period parameter can take one of the following values:

  • “year”
  • “quarter”
  • “month”
  • “week”
  • “day”
  • “hour”
  • “minute”
  • “second”

For example, suppose you have a data set that includes a column for order dates and you want to create a new column that shows the number of days between the order date and the current date. You can use the dateDiff function to perform the calculation.

Example

#Start#
dateDiff(OrderDate, now(), "day")
#End#

 

This expression would calculate the difference between the OrderDate and the current date, expressed in days, and return the result in the new column. Note that the now() function is used to get the current date and time.