Skip to main content

Notifications

Copilot Studio - General
Unanswered

Getting the right date format

(1) ShareShare
ReportReport
Posted on by 18
Hi, 
  I need some help working with dates , adaptive cards and Http requests.  Using CoPilot Studio for the first time, so bear with me
 
  My Adaptive card looks like this: 
 
   When the user selects a date, it is coming back to me in the format dd/mm/yyyy (even if I try to change the format in the card itself, nothing happens)
 
   In order to send the date to my Http call, I need the date to be in the format yyyy-mm-dd with the time element in the format 'T00:00:00.000Z'  
 
   I tried creating a variable setting it's value. But in the Set Variable function, using the datetimeformat gives me the following error 
 
 
 
 
 
 
   So I tried creating a formula like 
Year(Topic.startDate) + "-" + Month(Topic.startDate) + "-" + Day(Topic.startDate) + "T00:00:00.000Z")
 
   But this is falling over with an error that says 'cannot convert '-' into a number'  I have tried putting the whole thing into a 'Text' call, individual parts into a Text call.  Still get the same error.  I'm stumped.  
 
   Can somebody please help?  Goal is to to take the date entered by the user and send it to the Http request in the format 'YYYY-DD-DDT00:00:00.000Z' 
 
Thanks 
  • David_MA Profile Picture
    David_MA 8,970 on at
    Getting the right date format
    You can use the following expression:
     
    formatDateTime(parseDateTime(triggerBody()['text'],'en-us','dd/MM/yyyy'),'yyyy-MM-dd')
     
     
    Replace triggerBody()['text'] with the dynamic value that contains your date in the format dd/mm/yyyy. 

    This part of the expression tells Power Automate that you have a string value that you want to convert to an ISO8601 formatted date: parseDateTime(triggerBody()['text'],'en-us','dd/MM/yyyy'). 
     
    Then the formatDateTime expression converts the ISO8601 date to your desired format.
  • HenryJammes Profile Picture
    HenryJammes on at
  • CP-19070958-0 Profile Picture
    CP-19070958-0 18 on at
    Getting the right date format
    Thank you Henry.  That helps.  
     
    Would you point me to the right place for functions that I can use in CoPilot studio please, if you don't mind. I can't find the right source. 
  • HenryJammes Profile Picture
    HenryJammes on at
    Getting the right date format
    I think got this to work, like this:
     
     
    The Text function in Power Fx can output a date in what is called the UTC format.
     
    Text(Topic.SelectedDate, DateTimeFormat.UTC)
    

    But because it's not a date/time, you may find yourself with a wrong date being sent, given the time zone different between the user and UTC (I'm not exactly sure what your API endpoint expects).
     
    You can offset it by using this formula:
     
    Text(DateAdd(Topic.SelectedDate, - TimeZoneOffset(Topic.SelectedDate), TimeUnit.Minutes), DateTimeFormat.UTC)
     
     
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,508

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,839

Leaderboard