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
thQS
Frequent Visitor

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
Microsoft
Microsoft

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

thQS
Frequent Visitor

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

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,356)