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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Add Hours to a Date an...
Power Apps
Unanswered

Add Hours to a Date and Time

(0) ShareShare
ReportReport
Posted on by 28

Hi, 

 

I have a question on how to add hours to a certain time. The problem is that i want to have the date be changed if it is the next day.
Example:        Start Date:    March 1st, 22.00h  --> Add 6 hours   -->  End Date: March 2nd, 04.00h

 

I created a Sharepoint List with to write data to. 

- Collum 1: Duration (Text)
- Collum 2: Start Date (Date and Time)

- Collum 3: End Date (Date and Time)

I have set up a form with the folowing Datafields

- Duration: A dropdown with the folowing Values:   "2 hours", "3 hours", "12 hour", "15 Days")
- A start Time : 1 Datapicker with a Date and 2 dropdowns (1 for the hours, 1 for the minutes) (default when I generate the form, datasource = Sharepoint List)

- An End Time: 1 Datapicker with a Date and 2 dropdowns (1 for the hours, 1 for the minutes).(default when I generate the form, datasource = Sharepoint List).

 

I want the end time to depend on the Start Time and End Time. 
How Do i Change the default values for the end time datapicker and dropdowns?  

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @thQS 

    Per the documentation for DateAdd

    DateAdd( DateTime, Addition [, Units ] )
    
    DateTime - Required. Date/time value to operate on.
    Addition - Required. Number, in Units, to add to the DateTime.
    Units - Optional. The type of Units to add: Milliseconds, Seconds, Minutes, Hours, Days, Months, Quarters, or Years. If not specified, Days are used.

    In your case for example, you would set the Default property of a datepicker to DateAdd(Now(), 6, Hours)

  • Rodrigo Hentz Profile Picture
    on at

    Hi @thQS how are you? Thanks for using ou community.

     

    @thQS did you check the informations provided by @Drrickryp . Do you have any question or doubts?

     

    Please let us know about and if needed add an image about the issue if you have.

     

    Please let me know if this information helped on your question.

     

    Regards.

    Rodrigo Hentz

    Microsoft Support Engineer

  • Verified answer
    thQS Profile Picture
    28 on at

    I can't seem get that to work in my case. 
    Adding hours to Now() is no problem. 
    The Now Has to be replaced by 3 other fields, 1 Datepicker and 1 dropbox for hours and 1 dropbox for minutes. 

    I ended up setting up an If() where I test the duration and the start time. 
    Ex: when the start time is 22.00h and the duration is 3hours , than default for end time =  selected date + 1
    Ex2: when start time is 11.00h and duration is 6hours , that selected date is the default for the end time.

     

    It's a little inefficient, but it ended up solving the problem.

  • IPC_ahaas Profile Picture
    1,387 Moderator on at

    According to the documentation:

    DateAdd, DateDiff, and TimeZoneOffset functions in Power Apps - Power Platform | Microsoft Learn

     

    The format should be:

    DateAdd(Now(),6,TimeUnit.Hours)

     

    Without "TimeUnit." the code didn't work for me.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard