Date calculations...add days() is good...but what about subtract days()? - InfoPath Dev
in

InfoPath Dev

Date calculations...add days() is good...but what about subtract days()?

Last post 04-11-2012 05:11 AM by Jimmy. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-11-2012 02:18 AM

    Date calculations...add days() is good...but what about subtract days()?

    Thanks again for help with my first issue everybody!  Round two...DING!

     So I inherited this form from another "programmer" but I'm not tracking on some of the stuff.  Basically a co-worker said, "Oh, that...yeah he found that on google. I have no idea what it means..."  Yup, that's about as much light I can shine on it too.  Substring madness is making my head explode.  And what is floor()?

    Here's the example.  We have 4 date fields that work in tandem

    LeaveStartDate - Whatever day you start leave
    LeaveEndDate - Leave Start Date + 14 days (for a theoretical 15 days leave) It's always 15 days, we're in the military, it's for rest and relaxation while deployed.
    TravelDate - This is 2 days before your Leave Start Date
    LeaveReturnDate - This is 3 days after your Leave End Date

    So, I enter the leave start date and the adddays() function works pretty well, so Leave End Date gets populated.  Very nice.

    However, Travel Date should be calculated (with a rule?), so adddays(LeaveEndDate, -2) should work, right?  Wrong.  NaN is the result.  Which I assume is not a number, because adddays is for adding, not subtracting.  Maybe I could get it to do it though, or maybe someone could tell me how.

    Currently the unchecked rule for Travel Date is this:

    -conditions: TRAVELDATE is not blank and LEAVESTARTDATE is not blank
      -Set a field's value TRAVELDATECHECK  (by the way, I have no idea where this field is (TRAVELDATECHECK, so I have tried TRAVELDATE in this position (or ".") and it still doesn't work.  I'm assuming it worked at some point.)
       -(number(substring(LEAVESTARTDATE, 9, 2)) + floor((153 * (number(substring(LEAVESTARTDATE, 6, 2)) + 12 * (floor((14 - number(substring(LEAVESTARTDATE, 6, 2))) / 12)) - 3) + 2) / 5) + (number(substring(LEAVESTARTDATE, 1, 4)) + 4800 - (floor((14 - number(substring(LEAVESTARTDATE, 6, 2))) / 12))) * 365 + floor((number(substring(LEAVESTARTDATE, 1, 4)) + 4800 - (floor((14 - number(substring(LEAVESTARTDATE, 6, 2))) / 12))) / 4) - floor((number(substring(LEAVESTARTDATE, 1, 4)) + 4800 - (floor((14 - number(substring(LEAVESTARTDATE, 6, 2))) / 12))) / 100) + floor((number(substring(LEAVESTARTDATE, 1, 4)) + 4800 - (floor((14 - number(substring(LEAVESTARTDATE, 6, 2))) / 12))) / 400) - 32045) - (number(substring(LEAVESTARTDATE, 9, 2)) + floor((153 * (number(substring(., 6, 2)) + 12 * (floor((14 - number(substring(., 6, 2))) / 12)) - 3) + 2) / 5) + (number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) / 12))) * 365 + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) / 12))) / 4) - floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) / 12))) / 100) + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) / 12))) / 400) - 32045)

    And then the ReturnFromLeave field I thought for sure would work with adddays(LEAVEENDDATE, 3), but it doesn't. I also get NaN.

    Additional info: I have Studio 2008 on my computer, but I do not know why I can't open up code on stuff.  I installed the special Microsoft Visual Studio Tools for Applications, but whenever I try to open up via the programming menu, it gives me the following error: "Infopath cannot starts MVSTA. Infopath cannot create the Visual Basic or C# project. The locations for the VB or C# project cannot be found or cannot be accessed."

    If I can do this without programming it would be good, but at this point anything to get this thing working would be better.

    Thanks!

    Joe

     

  • 04-11-2012 03:11 AM In reply to

    Re: Date calculations...add days() is good...but what about subtract days()?

    K, default value with adddays(LEAVESTARTDATE, -2) works well.  Default value was something I learned from my last question and I forgot to try that last night.

    Still tinkering with ReturnFromLeave.

  • 04-11-2012 05:11 AM In reply to

    Re: Date calculations...add days() is good...but what about subtract days()?

    I think you need to ensure that your logic is set up so that rules fire in the right order, e.g. that you don't use addDays(field, number) when field is still blank.  I think that if you use default value formulas for everything this will probably work out without too much finagling.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.