web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Modern DatePicker defa...
Power Apps
Answered

Modern DatePicker defaultDate doesn't show correct date.

(1) ShareShare
ReportReport
Posted on by 54
Hi,
 
has anyone experienced an issue with the modern DatePicker where it displays the wrong date set in the defaultDate property? I’m not sure whether the problem is in the rendering. I don’t understand what’s going on. Thanks for any advice on how to avoid this ambiguous behavior of the DatePicker.

I use Dataverse tables as source.
 
 
 
- datp_datum_pozadavky_vsa_5:
    Control: ModernDatePicker@1.0.0
    Properties:
      BorderStyle: =""
      DefaultDate: |-
        =//toto funguje pre klasicku tabulku
        //DataTable_aktivity_2.Selected.Datum
 
        //pre potreby prepnutia na modernTable
        //If(tgl_zobraz_modernTable.Checked; modernTable_aktivity.Selected.Datum;DataTable_aktivity_2.Selected.Datum)
 
        DataTable_aktivity_2.Selected.Datum
      EndDate: =Today()+10
      Font: =""
      FontWeight: =""
      Format: =DatePickerFormat.Short
      Height: =29
      IsEditable: =true
      OnChange: |
        =Select(btn_SaveControl_pred_ulozenim)
      Placeholder: ="Vyberte dátum…"
      Size: =12
      StartDate: "=If( \r\n    var_editovatelny_vsa = true,\r\n        Year(2024)\r\n        ,\r\n        Today()-4\r\n)      \r\n\r\n//funkcne - pracuje len s pracovnymi dnami\r\n/*\r\nIf( \r\n    var_editovatelny_vsa = true;\r\n        Year(2024)\r\n        ;\r\n\r\n        If(Weekday(Today()) in [\"2\";\"3\";\"4\";\"5\"];\r\n            Today()-6\r\n            ;\r\n            Today()-4\r\n        )\r\n        \r\n        \r\n*/"
      StartOfWeek: =StartOfWeek.Monday
      ValidationState: =If(IsBlank(Self.SelectedDate),"Error","None")
      Visible: |-
        =true
        //If (var_velkost_zobrazovanej_tabulky_polka = true And var_vykaz_do_buducna = false; true;false)
 
        //var_velkost_zobrazovanej_tabulky_polka
      Width: |+
        =150
      X: =lbl_datum_5.X+lbl_datum_5.Width
 
 
 
Thanks for any advice, Tom.
Categories:
I have the same question (0)
  • Suggested answer
    Haque Profile Picture
    3,653 on at
    Hi @TomGaz,
     
    Which time zone you are in? How it is wrong date set? Coul you please post the format you want.
    • The modern DatePicker control may interpret the date-time value differently than expected, especially if the field is configured as "Date Only" but the underlying data includes time.
    • Rendering quirks in the modern DatePicker can cause it to display a date off by one day if the time zone offset pushes the date backward or forward.
     

    Here are some suggestions to help you troubleshoot and fix the problem:

    Check the Dataverse field type: Confirm if Datum in your Dataverse table is configured as "Date Only" or "Date and Time." If it’s Date and Time, the time portion (often UTC) can cause the date to shift when displayed in the DatePicker.

    Strip the time portion explicitly: You can try to force the date value to ignore the time by using a formula like:
    DateValue(DataTable_aktivity_2.Selected.Datum) or DateValue(modernTable_aktivity.Selected.Datum) - 
    This extracts only the date part and can prevent off-by-one-day errors caused by time zone shifts.

    Test with a static date: Temporarily set DefaultDate to a fixed date like DateValue("2024-06-01") to verify if the control renders the date correctly. This helps isolate whether the issue is with the data or the control.

    Consider time zone adjustments: If your users are in different time zones, you might need to adjust the date value by adding or subtracting hours before passing it to the DatePicker.

     
     

    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!
  • Suggested answer
    11manish Profile Picture
    3,333 on at
    Issue is not your formula
     
    It’s due to:
    • Timezone conversion
    • Rendering timing
    • Modern control quirks
    Best fix: use DateValue() + variable binding
  • CarlosFigueira Profile Picture
    Microsoft Employee on at
    The problem is in the StartDate property of the date picker control. If the value of var_editovatelny_vsa is false, then the smallest possible date for the date picker will be <<Today() - 4>> - which today (April 2nd) would be 2026-03-29, the value you're seeing in your scenario. Since the default date is less than the minimum possible date, the control is choosing the smallest allowed date instead.
     
    If you update the value of the StartDate property to a value before the selected date in the data table, you should see it working properly.
     
    By the way, if you want the StartDate value to be the year 2024 if that variable is true, then you should use Date(2024;1;1) instead of Year(2024):
    If( 
        var_editovatelny_vsa = true;
            Date(2024;1;1) // not Year(2024)
            ;
            Today()-4
    )      
     
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Hi @TomGaz,
    I believe that your problem is more fundamental - Data Tables are still in preview and their .Selected.FieldName property can be unreliable. If you try a Gallery with the same Items and it works, then that is your problem.
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Hi @TomGaz,
    A quick follow-up to see if you received the answer you were looking for. Happy to assist further if not.
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn   
  • Suggested answer
    TomGaz Profile Picture
    54 on at
    Hi, 

    thanks a lot for all reply. 
    @CarlosFigueira 
    your answer pointed me in the right direction. 
    When I changed my existing code to:
    If(
        var_editovatelny_vsa = true;
            Date(2024;1;1)
            ;
            //not working
            //If(DataTable_aktivity_2.Selected.Datum <= Today()-4; DataTable_aktivity_2.Selected.Datum;Today()-4)
     
            If(DataTable_aktivity_2.Selected.Datum <= Today()-4; Date(2024;1;1);Today()-4)
     
    )  
     
    It helped but not completely. I agree with @11manish that there is also a problem with rendering.
    I had to downgrade the application version to get to the modern datepicker before the update. Because after the update, the datepicker is unusable for me. Here are both codes 1.datepicker is modern but before the update, the second is after the update.
    In the first one, I still left StartDate and EndDate -> it works like clockwork.
    However, after the upgrade (second in order) -> it shows errors. It does not always fail, so I agree with @11manish that there is also a problem with the rendering timing.

    DatePicker before modernization:
    - datp_datum_pozadavky_vsa_5:
        Control: DatePicker@0.0.46
        Properties:
          AccessibleLabel: =
          DisplayMode: |-
            =If(
                var_editovatelny_vsa = true,
                DisplayMode.Edit,
                With(
                    {
                        sel: If(
                            tgl_zobraz_modernTable.Checked,
                            modernTable_aktivity.Selected,
                            DataTable_aktivity_2.Selected
                        )
                    },
                    If(
                        Text(sel.'Money exportovano') = "Ano"
                            Or Text(sel.Schváleno) = "Ano",
                        DisplayMode.Disabled,
                        If(
                            (sel.Datum >= DateAdd(Today(), -4, TimeUnit.Days)) &&
                            (
                                sel.Pracovník = varUzivatel  
                            )
                            &&
                            !StartsWith(sel.Popis, "Čas na cestě"),
                            DisplayMode.Edit,
                            DisplayMode.View
                        )
                    )
                )
            )
          EndDate: =Today()+10
          FontSize: =12
          Format: ='DatePickerCanvas.Format'.Short
          Height: =29
          IsEditable: =true
          LayoutMaxHeight: =
          LayoutMaxWidth: =
          OnChange: |
            =Select(btn_SaveControl_pred_ulozenim)
          SelectedDate: |-
            =//pre potreby prepnutia na modernTable
            If(tgl_zobraz_modernTable.Checked, modernTable_aktivity.Selected.Datum,DataTable_aktivity_2.Selected.Datum)
          StartDate: |+
            =If(
                var_editovatelny_vsa = true,
                    Year(2024)
                    ,
                    Today()-4
            )      
          StartOfWeek: ="Monday"
          ValidationState: =If(IsBlank(Self.SelectedDate),"Error","None")
          Visible: |-
            =If (var_velkost_zobrazovanej_tabulky_polka = true And var_vykaz_do_buducna = false, true,false)
     
            //var_velkost_zobrazovanej_tabulky_polka
          Width: |+
            =150
          X: =lbl_datum_5.X+lbl_datum_5.Width
          Y: =
    ------------------------------------------
     

    DatePicker after modernization:
    - datp_datum_pozadavky_vsa_6:
        Control: ModernDatePicker@1.0.0
        Properties:
          BorderStyle: =""
          DefaultDate: |-
            =
            //pre potreby prepnutia na modernTable
            If(tgl_zobraz_modernTable.Checked, modernTable_aktivity.Selected.Datum,DataTable_aktivity_2.Selected.Datum)
          DisplayMode: "=If(\r\n    var_editovatelny_vsa = true,\r\n    DisplayMode.Edit,\r\n    With(\r\n        {\r\n            sel: If(\r\n                tgl_zobraz_modernTable.Checked,\r\n                modernTable_aktivity.Selected,\r\n                DataTable_aktivity_2.Selected\r\n            )\r\n        },\r\n        If(\r\n            Text(sel.'Money exportovano') = \"Ano\" \r\n                Or Text(sel.Schváleno) = \"Ano\",\r\n            DisplayMode.Disabled,\r\n            If(\r\n                (sel.Datum >= DateAdd(Today(), -4, TimeUnit.Days)) &&\r\n                (\r\n                    \r\n                    sel.Pracovník = varUzivatel   \r\n                ) \r\n                &&\r\n                !StartsWith(sel.Popis, \"Čas na cestě\"),\r\n                DisplayMode.Edit,\r\n                DisplayMode.View \r\n            )\r\n        )\r\n    )\r\n)\r\n\r\n\r\n\r\n\r\n"
          EndDate: =//Today()+10
          Font: =""
          FontWeight: =""
          Format: =DatePickerFormat.Short
          Height: =29
          IsEditable: =true
          OnChange: |
            =Select(btn_SaveControl_pred_ulozenim)
          Placeholder: ="Vyberte dátum…"
          Size: =12
          StartDate: "=If( \r\n    var_editovatelny_vsa = true,\r\n        Date(2024,1,1)\r\n        ,\r\n        //not working\r\n        //If(DataTable_aktivity_2.Selected.Datum <= Today()-4; DataTable_aktivity_2.Selected.Datum;Today()-4)\r\n\r\n        If(DataTable_aktivity_2.Selected.Datum <= Today() -4, Date(2024,1,1),Today() -4)\r\n\r\n)     "
          StartOfWeek: =StartOfWeek.Monday
          ValidationState: =If(IsBlank(Self.SelectedDate),"Error","None")
          Visible: |-
            =If (var_velkost_zobrazovanej_tabulky_polka = true And var_vykaz_do_buducna = false, true,false)
     
            //var_velkost_zobrazovanej_tabulky_polka
          Width: =100
          X: =lbl_datum_5.X+lbl_datum_5.Width


    Resault:
     
    When I also commented out StartDate, it seems that the problem does not occur. Which is good news, but I need to do the same with the StartDate and EndDate properties.

    Thanks for any advice.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard