DateTimePicker (Coming soon)

Not supported by Chat apps. Support by Chat apps coming soon.

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

It accepts text input from users, but features an interactive date and time selector that helps users enter formatted dates and times. If users enter a date or time incorrectly, the widget shows an error that prompts users to enter the correct format.

Chat apps receive and can process the value of user-entered dates and times during form input events. For details about working with form inputs, see Receive form data.

Example

The following image displays a card consisting of a DateTimePicker widget:

A card message in Google Chat depicting a Text Paragraph widget.
Figure 1: A card message in Google Chat depicting three DateTimePicker widgets: one for selecting both date and time, one for just date, and one for just time.

Here's the card's JSON:

JSON

{
  "cardsV2": [
    {
      "cardId": "exampleCard",
      "card": {
        "sections": [
          {
            "widgets": [
              {
                "textParagraph": {
                  "text": "A datetime picker widget with both date and time:"
                }
              },
              {
                "divider": {}
              },
              {
                "dateTimePicker": {
                  "name": "date_time_picker_date_and_time",
                  "label": "meeting",
                  "type": 'DATE_AND_TIME',
                }
              },
              {
                "textParagraph": {
                  "text": "A datetime picker widget with just date:"
                }
              },
              {
                "divider": {}
              },
              {
                "dateTimePicker": {
                  "name": "date_time_picker_date_and_time",
                  "label": "Choose a date",
                  "type": 'DATE_ONLY',
                }
              },
              {
                "textParagraph": {
                  "text": "A datetime picker widget with just time:"
                }
              },
              {
                "divider": {}
              },
              {
                "dateTimePicker": {
                  "name": "date_time_picker_date_and_time",
                  "label": "Select a time",
                  "type": 'TIME_ONLY',
                }
              },
            ]
          }
        ]
      }
    }
  ]
}

DateTimePicker 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 datetime picker 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 enter a date, time, or datetime.

Specify text that helps the user enter the information your app needs. For example, if users are setting an appointment, then a label like "Appointment date" or "Appointment date and time" might work well.

type

enum ( DateTimePickerType )

What kind of date and time input the datetime picker supports.

valueMsEpoch

string ( int64 format)

The value displayed as the default value before user input or previous user input, represented in milliseconds ( Epoch time ).

For DATE_AND_TIME type, the full epoch value is used.

For DATE_ONLY type, only date of the epoch time is used.

For TIME_ONLY type, only time of the epoch time is used. For example, to represent 3:00 AM, set epoch time to 3 * 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 not set, it uses the user's time zone setting on the client side.

onChangeAction

object ( Action )

Triggered when the user clicks Save or Clear from the datetime picker interface.

DateTimePickerType

Enums
DATE_AND_TIME The user can select a date and time.
DATE_ONLY The user can only select a date.
TIME_ONLY The user can only select a time.

Action

An action that describes the behavior when the form is submitted. For example, an Apps Script can be invoked 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 button on 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 is not 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 1 day, 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 button on 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 is not 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.