Changing the Date to Display Based on the Selected Option

If you want to change the date to display based on the option you select, use an IF function to write a conditional expression with the Date or the Date and time field. However, if you specify the Date or the Date and time field directly in the formula, the calculated results will be treated as UNIX time and not displayed in date and time format (Example: November 13, 2020 -> 1605225600). If you use a DATE_FORMAT function, you can convert the Date or the Date and time into a string in the specified date and time format.

Formula Example
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")))

The date will automatically be displayed in Japanese format if you select "Japanese Style", US format if you select "American Style", or British format if you select "British Style".

For details on the IF function, see the "IF Function: Changing the Value to Display Depending on the Condition" page.

Example

The following example shows how to combine IF function and DATE_FORMAT function to display the date in the appropriate format based on the country you select.

Image of the created app:

  1. Click the Settings button Settings button on the upper right of the View, and select the "Form" tab.

  2. From the parts list shown in the left side, drag and drop the Date field.
    Leave the default field code (Date) as is.

  3. Select the Text field and the Radio Button field in the parts list, and place them in the form.

  4. Open the screen to set the Radio Button field, and then change the field name to "Display method"and the field code to "Display_method".
    Set "Japanese Style", "American Style", and "British Style" as options.

  5. Click Save on the screen to set a radio button.

  6. Open the screen to set the Text field, and enter "date" as the field name.

  7. Select "Calculate automatically", and enter the formula.

    • Formula to change the date display according to the country selected
      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")))
  8. Click Save on the screen to set the Text field.

  9. Click Save Form on the upper left side of the screen, and then click Update App on the upper right side of the screen.

Now, the date is displayed using the date format selected.