Date time picker

The DateTimePicker widget lets users input a date, a time, or both a date and a time.

Users can input text or use the picker to select dates and times. If users input an invalid date or time, the picker shows an error that prompts users to input the information correctly.

To process the date and time values that users input, see Receive form data.

Example

The following displays a card consisting of three different types of DateTimePicker widgets:

JSON representation and fields

JSON representation
{
  "name": string,
  "label": string,
  "type": enum (DateTimePickerType),
  "valueMsEpoch": string,
  "timezoneOffsetDate": integer,
  "onChangeAction": {
    object (Action)
  }
}
Fields
name

string

The name by which the DateTimePicker is identified in a form input event.

For details about working with form inputs, see Receive form data.

label

string

The text that prompts users to input a date, a time, or a date and time. For example, if users are scheduling an appointment, use a label such as Appointment date or Appointment date and time.

type

enum (DateTimePickerType)

Whether the widget supports inputting a date, a time, or the date and time.

valueMsEpoch

string (int64 format)

The default value displayed in the widget, in milliseconds since Unix epoch time.

Specify the value based on the type of picker ( DateTimePickerType):

  • DATE_AND_TIME : a calendar date and time in UTC. For example, to represent January 1, 2023 at 12:00 PM UTC, use 1672574400000.
  • DATE_ONLY : a calendar date at 00:00:00 UTC. For example, to represent January 1, 2023, use 1672531200000.
  • TIME_ONLY : a time in UTC. For example, to represent 12:00 PM, use 43200000 (or 12 * 60 * 60 * 1000).
timezoneOffsetDate

integer

The number representing the time zone offset from UTC, in minutes. If set, the valueMsEpoch is displayed in the specified time zone. If unset, the value defaults to the user's time zone setting.

onChangeAction

object (Action)

Triggered when the user clicks Save or Clear from the DateTimePicker interface.

DateTimePickerType

Enums
DATE_AND_TIME Users input a date and time.
DATE_ONLY Users input a date.
TIME_ONLY Users input a time.

Action

An action that describes the behavior when the form is submitted. For example, you can invoke an Apps Script script to handle the form. If the action is triggered, the form values are sent to the server.

JSON representation
{
  "function": string,
  "parameters": [
    {
      object (ActionParameter)
    }
  ],
  "loadIndicator": enum (LoadIndicator),
  "persistValues": boolean,
  "interaction": enum (Interaction)
}
Fields
function

string

A custom function to invoke when the containing element is clicked or othrwise activated.

For example usage, see Create interactive cards.

parameters[]

object (ActionParameter)

List of action parameters.

loadIndicator

enum (LoadIndicator)

Specifies the loading indicator that the action displays while making the call to the action.

persistValues

boolean

Indicates whether form values persist after the action. The default value is false.

If true, form values remain after the action is triggered. To let the user make changes while the action is being processed, set LoadIndicator to NONE. For card messages in Chat apps, you must also set the action's ResponseType to UPDATE_MESSAGE and use the same cardId from the card that contained the action.

If false, the form values are cleared when the action is triggered. To prevent the user from making changes while the action is being processed, set LoadIndicator to SPINNER.

interaction

enum (Interaction)

Optional. Required when opening a dialog.

What to do in response to an interaction with a user, such as a user clicking a button in a card message.

If unspecified, the app responds by executing an action —like opening a link or running a function—as normal.

By specifying an interaction, the app can respond in special interactive ways. For example, by setting interaction to OPEN_DIALOG, the app can open a dialog. When specified, a loading indicator isn't shown.

Supported by Chat apps, but not Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.

ActionParameter

List of string parameters to supply when the action method is invoked. For example, consider three snooze buttons: snooze now, snooze one day, or snooze next week. You might use action method = snooze(), passing the snooze type and snooze time in the list of string parameters.

To learn more, see CommonEventObject.

JSON representation
{
  "key": string,
  "value": string
}
Fields
key

string

The name of the parameter for the action script.

value

string

The value of the parameter.

LoadIndicator

Specifies the loading indicator that the action displays while making the call to the action.

Enums
SPINNER Displays a spinner to indicate that content is loading.
NONE Nothing is displayed.

Interaction

Optional. Required when opening a dialog.

What to do in response to an interaction with a user, such as a user clicking a button in a card message.

If unspecified, the app responds by executing an action —like opening a link or running a function—as normal.

By specifying an interaction, the app can respond in special interactive ways. For example, by setting interaction to OPEN_DIALOG, the app can open a dialog.

When specified, a loading indicator isn't shown.

Supported by Chat apps, but not Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.

Enums
INTERACTION_UNSPECIFIED Default value. The action executes as normal.
OPEN_DIALOG

Opens a dialog, a windowed, card-based interface that Chat apps use to interact with users.

Only supported by Chat apps in response to button-clicks on card messages.

Not supported by Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.

Troubleshoot

When a Google Chat app or card returns an error, the Chat interface surfaces a message saying "Something went wrong." or "Unable to process your request." Sometimes the Chat UI doesn't display any error message, but the Chat app or card produces an unexpected result; for example, a card message might not appear.

Although an error message might not display in the Chat UI, descriptive error messages and log data are available to help you fix errors when error logging for Chat apps is turned on. For help viewing, debugging, and fixing errors, see Troubleshoot and fix Google Chat errors.