Function to round time UP to nearest hour? - InfoPath Dev
in

InfoPath Dev

Function to round time UP to nearest hour?

Last post 09-10-2015 07:44 AM by Hilary Stoupa. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 09-04-2015 07:28 AM

    • Sailor
    • Top 75 Contributor
    • Joined on 09-15-2009
    • Canada
    • Posts 107

    Function to round time UP to nearest hour?

    Hello, Due to InfoPath not being able to add/subtract time out of the box, I spent multiple hours figuring out how to subtract start and end time. So now I have a result formatted as string, but I want to ROUND UP to the nearest hour. So for 00:25 I want it rounded to 01:00, and 01:40 to 02:00, etc. Then I need the sum of this result (they are in a repeating table). With the results formatted as a string, I don't imagine I can using the Ceiling function...

    Here is what I've done to create the Elapsed_Time

    concat(substring(concat(substring-before(../my:Total_Minutes div 60, "."), ":", ../my:Total_Minutes mod 60), 1, contains(../my:Total_Minutes div 60, ".") * string-length(concat(substring-before(../my:Total_Minutes div 60, "."), ":", ../my:Total_Minutes mod 60))), substring(concat(../my:Total_Minutes div 60, ":", ../my:Total_Minutes mod 60), 1, not(contains(../my:Total_Minutes div 60, ".")) * string-length(concat(../my:Total_Minutes div 60, ":", ../my:Total_Minutes mod 60))))

    Using the Total_Minutes field

    substring(((substring-before(../my:End_Time, ":") * 60) + substring-before(substring-after(../my:End_Time, ":"), ":")) - ((substring-before(../my:Start_Time, ":") * 60) + substring-before(substring-after(../my:Start_Time, ":"), ":")), 1, (../my:Start_Time != "" and ../my:End_Time != "") * string-length(((substring-before(../my:End_Time, ":") * 60) + substring-before(substring-after(../my:End_Time, ":"), ":")) - ((substring-before(../my:Start_Time, ":") * 60) + substring-before(substring-after(../my:Start_Time, ":"), ":"))))

  • 09-06-2015 09:26 PM In reply to

    • Sailor
    • Top 75 Contributor
    • Joined on 09-15-2009
    • Canada
    • Posts 107

    Re: Function to round time UP to nearest hour?

    I'm hoping someone will come to my rescue!
  • 09-09-2015 03:00 PM In reply to

    Re: Function to round time UP to nearest hour?

    Sorry, I'd help but most of those complex time formulas are beyond me.... is ElapsedTime being set by a rule or by a default value? I guess I'm wondering if you can't check the string after the ":" to see if it is anything other than "00" and then do something to increment the string before the ":"?
    Hilary Stoupa

  • 09-10-2015 06:17 AM In reply to

    • Sailor
    • Top 75 Contributor
    • Joined on 09-15-2009
    • Canada
    • Posts 107

    Re: Function to round time UP to nearest hour?

    Thank you Hilary. I appreciate you looking. ElapsedTime is indeed a default value. And to be 100% honest these formulas are way beyond me too! I struggled for a long time, and was following an example I saw elsewhere, which did handle the time calculation...but now I need to do the rounding. I wonder...should I not be able to somehow use a new field to store this is a NUMBER, then use a round function to round up to the nearest 60?
  • 09-10-2015 07:44 AM In reply to

    Re: Function to round time UP to nearest hour?

    I'm not sure - I don't think the round function works like that... unless maybe you changed the ":" to a decimal....?
    Hilary Stoupa

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.