Time calculation issue when using \dateAddHours\"


Badge +2

In my gut, I feel I should know how to fix this.  Alas...I cannot.  I am working on a time-off request form for one of our managers and we are trying to come up with "creative" ways to get around not having a business days/hours function available to us.  Currently, I'm trying out a date calculation for single day requests where someone enters the date and time they want off, then adds the number of hours off in the next field. My calculated value says "add hours to this date/time to get the end time" (at least that's what I want it to say).  What I am finding, though, is that it works great, but with whole numbers only. If someone wants 2.5 hours off, it only calculates the 2 hours and does not include the additional 30 minutes.  

My formula:  

formatDate(dateAddHours(RequestBeginSingleControl,TotalHoursOffControl), "MM/dd/yyyy hh:mm tt")

Results:

YAAAYYYYY!!!

BOOOOOO!!!

My first question: "What am I doing wrong?".  Second question: "How do I fix this?"

Thank you in advance for your brain power during a holiday week!


8 replies

Badge +16

is there a date add minutes function?

You may have to do both?

add hours and minutes?

Userlevel 5
Badge +14

the function adds only whole number of hours by design, see documentation

216908_pastedImage_2.png

https://help.nintex.com/en-US/nintex2013/help/#Forms/RootCategory/Designer/Nintex.Forms.RuntimeFunctions.htm%3FTocPath%3… 

you will have to add hours and minutes separately as Cassy Freeman‌ suggests.

Badge +2

Thank you both!!  Now...can either of you help with determining what the formula should look like?  I separated the # of hours into 2 fields (# hrs and #mins).  I'm coming up empty with each attempt to get a formula that brings everything together.  I've just completely confused myself into almost giving up!!

Badge +6

Whyt not convert your 2.5 Hours to Minutes (2.5*60=150min) and then use the DateAddMinutes Function.

218099_pastedImage_1.png

My Calculated Field Formula:  formatDate(dateAddMinutes(Date,sum(Hours*60)),"MM/dd/yyyy hh:mm tt")

Userlevel 5
Badge +14

have you tried formula like

dateAddMinutes(dateAddHours(RequestBeginSingleControl,HoursToAdd),MinutesToAdd)
Userlevel 5
Badge +14

this approach have 2 drawbacks...

  1. it forces users to convert minutes from 1/60 system to 1/100 system. for quarters or half-an-hours it might be straightforward.  but do you know by head decimal number to type in for a value like 2:05?
  2. such a calculation is (might be) inaccurate, just because of above mentioned conversion.
    218123_pastedImage_2.png
Badge +6

While I hear and acknowledge your argument, I do not see any company policy allowing it's employees to apply for 5min leave, generally there is a standard which allows for half hours but not random amounts of minutes (I could be wrong but unlikely), I would instead add validation on the field to not allow random minutes. Imagine the nightmare random amounts of minutes would create for Payroll. 

Userlevel 5
Badge +14

No problem if decimal values fit your needs  happy.png

I just wanted to point out that in some scenarios one need to be careful

Reply