Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

UK Date format

Posted on 27 Nov 2024 16:40:29 by
Hello,
 
I have a dropdown (Session) pulling from a date and time field in SharePoint, that provides the date and start time of some training sessions. I would like the user to select the session they want to attend using the dropdown and then press a button to add a placeholder to their calendar, all of the sessions last 20 minutes so I have hard coded the end time increasing by 20 minutes. All works well until I get to a date bigger than 12, such as 13th December or 21st January and then I get a status 400 error, stating that string was not recognised as a valid DateTime value. Can anyone help me where I am going wrong please? 
 
 
Office365Outlook.V4CalendarPostItem(
 
    LookUp(Office365Outlook.CalendarGetTables().value,DisplayName="Calendar").Name,
//Event Title
    "Placeholder: Session 1",
 
//Session Start
    Text(DateAdd(DateTimeValue(Session.Selected.Value), -TimeZoneOffset(), TimeUnit.Minutes)),
 
//Session End
 
 
    Text(DateAdd(DateTimeValue(Session.Selected.Value), 20 +TimeZoneOffset(), TimeUnit.Minutes)),
 
   "(UTC+00:00) Dublin, Edinburgh, Lisbon, London"
)
 
Many Thanks
 
Michaela
  • timl Profile Picture
    timl 31,927 on 28 Nov 2024 at 16:34:39
    UK Date format
    Hi  MD-27111611-0
     
    Can you confirm that Session.Selected.Value is a string value, and holds a date that's formatted in "dd-mm-yyyy" format?
     
    If so, the following should work better. Note that the call to DateTimeValue should specify "en-GB" for UK dates.
    Also, the call to text should specify the month placeholder as 'mm' in lower case as opposed to uppercase (eg, "yyyy-mm-ddThh:mm:ssZ") 
     
     
     
    Office365Outlook.V4CalendarPostItem(
        LookUp(Office365Outlook.CalendarGetTables().value, DisplayName = "Calendar").Name,
        // Event Title
        "Placeholder: Session 1",
        // Session Start
        Text(
            DateAdd(
                DateTimeValue(Session.Selected.Value, "en-GB"),
                -TimeZoneOffset(),
                TimeUnit.Minutes
            ),
            "yyyy-mm-ddThh:mm:ssZ"
        ),
        // Session End
        Text(
            DateAdd(
                DateTimeValue(Session.Selected.Value, "en-GB"),
                20 - TimeZoneOffset(),
                TimeUnit.Minutes
            ),
            "yyyy-mm-ddThh:mm:ssZ"
        ),
        "(UTC+00:00) Dublin, Edinburgh, Lisbon, London"
    )
     
  • MD-27111611-0 Profile Picture
    MD-27111611-0 on 28 Nov 2024 at 10:59:01
    UK Date format
    Thanks SwatiSTW,
     
    Your explanation was really helpful. Although I am now getting a different error,  "language code null not supported".
    I have tried including "en" but still getting the error.
     
    Thanks again
     
    Michaela
  • Suggested answer
    SwatiSTW Profile Picture
    SwatiSTW 152 on 27 Nov 2024 at 17:09:15
    UK Date format
    The problem occurs because DateTimeValue(Session.Selected.Value) anticipates that the Session.Selected.Value will be in a format that PowerApps identifies as a valid DateTime. If the format does not comport with its expectations (e.g., MM/DD/YYYY versus DD/MM/YYYY), PowerApps may misinterpret or fail to interpret the value correctly when dealing with dates beyond the 12th of a month (e.g., 13/12/2023).

    Make sure that the Session dropdown value is returned in a format that is compatible with PowerApps if it is a date-time field. The Text function can be used to ensure that a consistent format is enforced.

    Try below code

    Office365Outlook.V4CalendarPostItem(
        LookUp(Office365Outlook.CalendarGetTables().value, DisplayName = "Calendar").Name,
        // Event Title
        "Placeholder: Session 1",
        // Session Start
        Text(
            DateAdd(
                DateTimeValue(Session.Selected.Value, "yyyy-MM-ddThh:mm:ssZ"),
                -TimeZoneOffset(),
                TimeUnit.Minutes
            ),
            "yyyy-MM-ddThh:mm:ssZ"
        ),
        // Session End
        Text(
            DateAdd(
                DateTimeValue(Session.Selected.Value, "yyyy-MM-ddThh:mm:ssZ"),
                20 - TimeZoneOffset(),
                TimeUnit.Minutes
            ),
            "yyyy-MM-ddThh:mm:ssZ"
        ),
        "(UTC+00:00) Dublin, Edinburgh, Lisbon, London"
    )
     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,151

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,845

Leaderboard