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 / Update form Input Date...
Power Apps
Answered

Update form Input Date to default to current date if not selected, otherwise report the values selected.

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Is there a way to code the reported hour and minutes to be the current value if unselected. but report the selections otherwise.

 

I have set the update as in the date card as follows.

Switch(IsBlank(HourValue1) || IsBlank(MinuteValue1), true, DateTimeValue(DateValue1.SelectedDate& "00:00"), DateTimeValue(DateValue1.SelectedDate&" "&HourValue1.Selected.Value&":"&MinuteValue1.Selected.Value))

 

In Summary, I require the date, hour and minutes to default to current date, hour and minutes if unselected, and to report the selections when selected. 

 

I have managed some success by selecting Today() on the default date and setting AllowEmptySelection to true on the hour and minute controls. That solves the problem if no selection is made, but not if a retroactive date is set.

 

I understand what if/else statements in nested Excel functions, but I am new to the Power Apps code syntax. 

Any guidance how to solve that riddle would be gratefully received. 

 

@BCBuizer , as you kindly resolved some the issues already, and offered guidance on this new query, please can you advise?

 

Categories:
I have the same question (0)
  • TheRobRush Profile Picture
    11,128 Moderator on at

    Here is one way

     

    When you click the button to load your form add this

     

    UpdateContext({defaultDate:true,defaultTime:true})

     

     

    Now on your date/minute/hour controls in that data card place this

    Date Control

     

    UpdateContext({defaultDate:false})

     

     

    Both Minute Controls

     

    UpdateContext({defaultTime:false})

     

     

    Update property of that data card will be

     

    If(!defaultDate || !defaultTime,
     DateValue1.SelectedDate + Time(Value(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value), 0), 
     currentTime //I put current time where I have currentTime updated eveyr second by an invisible timer, but you are free to put Now() as well
     )

     

    I also place thsi in my OnSuccess

    UpdateContext({defaultDate:Blank(),defaultTime:Blank()})

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @TheRobRush ,

    Not sure I'm following your guidance correctly, since I have run into early errors.

     

    Firstly, my load button has a workaround added:

     

    In the OnSelect Command

    Set(varFormData, Defaults('Course Review Report')); Navigate(Screen2);Navigate(Screen1);

     

    You would be forgiven for questioning why on earth would I append 2 navigation commands. It's because the form doesn't load otherwise. Anyway it works, and I appended your code as follows with no errors:

     

    Set(varFormData, Defaults('Course Review Report')); Navigate(Screen2);Navigate(Screen1);UpdateContext({defaultDate:true,defaultTime:true})

     

    When I add your second piece of code however, I run into an error on the Data card:

    mc00515_2-1678459323426.png

     

     

    mc00515_0-1678459159839.png

    The error message says

    mc00515_1-1678459213431.png

    Whatever that means?

     

     

  • TheRobRush Profile Picture
    11,128 Moderator on at

    I see what you did. the Update should remain the same for that card, it's what it sends to the list orwhatever is connected to it. That code should go on the OnChange of the 3 controls inside of it, first part on the calendar, and then the time version on the two time controls. 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @TheRobRush

     

    I seem to be honing into what you mean, but I am still there yet. I think I have followed you exactly, but not absolutely sure - the steps being in 4 screenshots, and an error that say Unexpected characters:

    PowerApps.jpg

    PowerApps2.jpg

    PowerApps3.jpg

    PowerApps4.jpg

     

  • TheRobRush Profile Picture
    11,128 Moderator on at

    click on the datacard, and then show me what its Update property is showing, and if it has red lines hover over them to show the more detailed error.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    mc00515_0-1678811565149.png

     

  • TheRobRush Profile Picture
    11,128 Moderator on at

    Change it to this, you had an error from when you changed the "currentTime" to Now(), left off a )

    If(!defaultDate || !defaultTime,
     DateValue1.SelectedDate + Time(Value(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value), 0), 
     Now()
     )

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    As ever, @TheRobRush , super and patient guidance.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Only problem now is the submission time has reverted to 17 hours ago if I leave the date as default "Toda()" and don't complete the hours and minutes, i.e. leave them at 00:00.

     

    My SharePoint regional settings are:

    mc00515_0-1678815171472.png

     

    Any ideas what I've missed off?

     

     

     

  • TheRobRush Profile Picture
    11,128 Moderator on at

    Put a label on your datacard and in its text property place the same thing as your update property

     

    If(!defaultDate || !defaultTime,
     DateValue1.SelectedDate + Time(Value(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value), 0), 
     Now()
     )

     

    then load your form and see what date & time it gives in that label before you change the time, and after. It's should be showing you the time & date that it currently is, until you change the time or date on the data card.

     

    IF it is not make sure that both your defaultTime and defaultDate are preset to true, (can check their values also by adding test labels with them as the default text) remmember, wherever we press the button we to load the form should have preset these to true, or even in the form reset (and call resetform() before loading the form)

    UpdateContext({defaultDate:true,defaultTime:true})

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 207 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 150 Super User 2026 Season 2

Last 30 days Overall leaderboard