Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

how to reset a datepicker defaultdate in a form

(0) ShareShare
ReportReport
Posted on by 34

 have a datepicker in the form that defaults to this Sunday of the week. If the user keeps this interface open, the default date will not change. If the user submits the form next week, the default date is still last Sunday. I just want to give the user a button to submit the form. How can I make the user refresh this default date automatically every time they submit, and set it to the Sunday date when the user submits? thanks. 

  • EricDa Profile Picture
    EricDa 34 on at
    Re: how to reset a datepicker defaultdate in a form

    Thanks. i think that will also do the trick, but let me try use veriable, it will update defaultdate too. 

  • EricDa Profile Picture
    EricDa 34 on at
    Re: how to reset a datepicker defaultdate in a form

    thanks. let me try this. 

  • Verified answer
    Re: how to reset a datepicker defaultdate in a form

    HI , @EricDa 

    If you always want to save the date after submitting the form as the Sunday of the time the user clicks the submit button. You can update this field:

    DataCard - Update: ï¼ˆThis determines what data you submit to the data source )

    Today()-Weekday(Today(),StartOfWeek.Monday)+1+6

     

    This way, no matter what the user chooses, the submission will always be the Sunday of the week on which the button is clicked.

     

    If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

     

    Best Regards,

    Yueyun Zhang

     

  • EricDa Profile Picture
    EricDa 34 on at
    Re: how to reset a datepicker defaultdate in a form

    thanks for reply, i have no problem with setting defaultdate of datepicker. as i mentioned, if today date is May 24, 2024, the defaultdate of datepicker is May 26, 2024. if user leave the app interface(form) open untill May 27, 2024, then submit the form on May 27, the defaultdate of datepikcer is still remain on May 26 which is not what i want. i also dont want to user to use resetform(), because user will lost all the fill in information in the form. 

  • Verified answer
    Gochix Profile Picture
    Gochix 1,933 on at
    Re: how to reset a datepicker defaultdate in a form

    @EricDa ,

     

    Set your defaultDate in datepicker to varDate

    then on your submit button:

    Set(varDate,
    DateAdd(Today(), 
     With({
     _sday:Weekday(Today(), StartOfWeek.Sunday)},
     If(
     _sday>=5, 8-_sday,1)),
     TimeUnit.Days)
    )


    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

  • EricDa Profile Picture
    EricDa 34 on at
    Re: how to reset a datepicker defaultdate in a form

    thanks for your reply, the datepicker is in the form, i cannot use reset() to reset it. i can only insert a icon into that datacardcontrol and set icon.onselect to hold reset(). but i dont want to user to click the icon, i only want to use click the submitform button. 

  • Re: how to reset a datepicker defaultdate in a form

    HI , @EricDa 

    According to your description, you want to always add the Sunday in your side.

    For example , this is my test data:

    vyueyunmsft_0-1716529075583.png

    We need to use this expression:

    DataCard - Default:
    If(Form1.Mode= FormMode.New ,Today()-Weekday(Today(),StartOfWeek.Monday)+1+6 , ThisItem.WeekStart)

    DataCard - Update: (This determines what data you submit to the data source )

    Today()-Weekday(Today(),StartOfWeek.Monday)+1+6

     

    Button- OnSelect:
    SubmitForm(Form1);ResetForm(Form1);

     

    If this reply can help you , you can click mark this reply as solution (Accept solution) which can help more people, thanks in advance! 

     

    Best Regards,

    Yueyun Zhang

     

  • mmbr1606 Profile Picture
    mmbr1606 10,444 on at
    Re: how to reset a datepicker defaultdate in a form

    hey @EricDa 

     

    can u try this in the default of date picker

    DateAdd(Today(), 7 - Weekday(Today()), Days)
    

     

    and this in button onselect:

    Reset(NextSundayPicker);
    SubmitForm(YourFormName); // Replace 'YourFormName' with the actual name of your form if you're submitting a form
    

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

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,495

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,822

Leaderboard