Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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:
If the
Conversation.LocalTimeZonesystem variable is set to a valid time zone from Noda Time, use that as the time zone.If the channel included the local time zone in the user's message, use that.
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 fromConversation.LocalTimeZoneand 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.
Open the topic in which you want to set the user's time zone.
Add a Set variable value node.
For Set variable, choose the
Conversation.LocalTimeZonesystem topic.For To value, enter one of the Zone ID values from the Noda Time website; for example,
America/Los_Angeles.
Add a Message node.
In the text box, enter "The local time zone is: ", then select Insert variable ({x}), and insert the system variable
Conversation.LocalTimeZone.Add a second Message node.
In the text box, enter "The local time zone offset is: ", then select Insert variable ({x}), and insert the system variable
Conversation.LocalTimeZoneOffset.Save and test the agent.
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.
Create a topic and add the trigger phrase "what time is it".
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.
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).
Add a Message node. Enter the message "The current date and time is {Topic.nowLocal}".
Test your agent in the Test agent pane to get the date and time in your time zone.