cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
thQS
Frequent Visitor

Add Hours to a Date and Time

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?  

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

3 REPLIES 3
Drrickryp
Super User
Super User

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)

rohentz
Community Support
Community Support

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

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.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,627)