/    /  Amazon QuickSight – formatDate

Amazon QuickSight – formatDate

 

In Amazon QuickSight, the formatDate function is used to convert a date to a string in a specified format.

Syntax

#Start#
formatDate(date, [format])
#End#

 

This function takes two arguments

 

  • date: is the date that you want to format.
  • format: is an optional parameter that specifies the format of the output. The format string should include special characters that are replaced with the corresponding parts of the date, such as “yyyy” for the year, “MM” for the month, “dd” for the day, and so on. If the format parameter is not provided, the function will return the date in the default format.

 

Here’s an example of how to use the formatDate function to convert a date to a string in the format “yyyy-MM-dd”

Example

 

#Start#
formatDate({OrderDate}, "yyyy-MM-dd")
#End#

 

This would produce a string that represents the date in the format “yyyy-MM-dd”. For example, if the OrderDate field contained the date “2023-02-22”, the above expression would produce the string “2023-02-22”.

 

If the format parameter is omitted, the function will return the date in the default format. The default format is determined by the regional settings of the analysis or the user’s browser.

 

Example

#Start#
formatDate({OrderDate})
#End#

 

This would produce a string that represents the date in the default format for the current region.

 

Note that the formatDate function returns a string, not a date. If you need to perform date arithmetic or other operations with the result, you may need to convert it back to a date using the toDate function.