Accommodate time zones

The Date and time entity captures a date and time in Coordinated Universal Time (UTC). However, you might want to display the date and time based on the user's location instead.

Prerequisites

How Copilot Studio determines the user's time zone

Copilot Studio follows these steps, in order, to determine the user's time zone:

  1. If the Conversation.LocalTimeZone system variable is set to a valid time zone from Noda Time, use that as the time zone.

  2. If the channel included the local time zone in the user's message, use that.

  3. Otherwise, use UTC as the time zone.

Get the user's time zone

Use these system variables to get information about the user's time zone:

  • Conversation.LocalTimeZone (read-write): Stores the user's time zone as a string. You can optionally set this variable to any time zone listed on the Noda Time website.

  • Conversation.LocalTimeZoneOffset (read-only): Gets the UTC offset from Conversation.LocalTimeZone and stores it as a time value.

Manually set the user's time zone

Copilot Studio automatically determines the user's time zone when your agent prompts the user for a date and time. You can also manually set the time zone.

  1. Open the topic in which you want to set the user's time zone.

  2. Add a Set variable value node.

    • For Set variable, choose the Conversation.LocalTimeZone system topic.

    • For To value, enter one of the Zone ID values from the Noda Time website; for example, America/Los_Angeles.

  3. Add a Message node.

  4. In the text box, enter "The local time zone is: ", then select Insert variable ({x}), and insert the system variable Conversation.LocalTimeZone.

  5. Add a second Message node.

  6. In the text box, enter "The local time zone offset is: ", then select Insert variable ({x}), and insert the system variable Conversation.LocalTimeZoneOffset.

  7. Save and test the agent.

    Screenshot of the Test agent pane.

Display the date and time in the local time zone

Copilot Studio stores the date and time in UTC. Before displaying a date and time to customers, add the time zone offset to convert the value to the user's local time zone.

In this example, we get the current date and time using the Power Fx Now() function, and then add the time zone offset. It isn't possible to use the Conversation.LocalTimeZoneOffset system variable directly in a Power Fx formula. Instead, we use a Set variable value node to create a variable and then assign it the value of Conversation.LocalTimeZoneOffset.

  1. Create a topic and add the trigger phrase "what time is it".

  2. In the authoring canvas, select Add node (+). Select Set a variable value.

    • For Set variable, create a variable named offset.

    • For To value, select the system variable Conversation.LocalTimeZoneOffset.

      Screenshot of a 'Set variable value' node assigning a value to the offset variable.

  3. Add a second Set variable value node.

    • For Set variable, create a variable named nowLocal.

    • For To value, enter the Power Fx formula DateAdd(Now(), Topic.offset, TimeUnit.Minutes).

      Screenshot of a 'Set variable value' node assigning a value to the nowLocal variable.

  4. Add a Message node. Enter the message "The current date and time is {Topic.nowLocal}".

  5. Test your agent in the Test agent pane to get the date and time in your time zone.

    Screenshot of an agent replying with the current date and time in the Test agent pane.