Selecting the date format to display from a set of options

記事番号:040744

By using an IF function and a DATE_FORMAT function, you can convert the date or the date and time into a character string that uses a specified date and time format.

As an example, this page explains how to change the displayed date format based on which country is selected in a Radio button field. The date will automatically be displayed in the Japanese date format if [Japanese style] is selected, the US date format if [American style] is selected, or the British date format if [British style] is selected.

Screenshot: A field set to display the date for multiple countries is outlined in red

Preparation

Place the following fields in the form and set their field names and field codes.

  • Date field
    • Field name and field code: "Date"
  • Text field
    • Field name and field code: Converted date
  • Radio button field
    • Field name: "Display method"; Field code: "Display_method"
    • Options: "Japanese style", "American style", "British style"

Screenshot: Placing a "Date" field on the "Form" tab Screenshot: Placing a "Text" field and a "Radio button" field on the "Form" tab Screenshot: The "Settings" icon (the gear-shaped icon) is highlighted Screenshot: The "Name" and "Options" sections in the settings of a "Radio button" field are highlighted

Setting up the formula

The formula in this example needs to be set for the Text field.

The content has been copied.
IF(Display_Method="Japanese Style", DATE_FORMAT(Date, "yyyy/MM/dd", "Etc/GMT"), IF(Display_Method="American Style", DATE_FORMAT(Date, "MM/dd/yyyy", "Etc/GMT"), DATE_FORMAT(Date, "dd/MM/yyyy", "Etc/GMT")))