topic Re: Math calculation problem! - Where is the help? ? ? in Adobe LiveCycle Discussions
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64981#M22691
<HTML><HEAD></HEAD><BODY>I had a lot of trouble with this too, thanks for the help. My solution also adds days for a leave form. The key for me was using the .formattedValue attribute and making sure the binding and value types for the time fields matched "HH:MM". My edit and display formats were "h:MM A".<BR /><BR /><BR /><BR />on the exit event:<BR /><BR /><BR /><BR />if ( HasValue(FromDate) and HasValue(ToDate) and HasValue(FromTime) and HasValue(ToTime) ) then<BR /><BR /> if ( FromDate == ToDate ) then<BR /><BR /> Total_Hours = 8 - ((Time2Num(FromTime.formattedValue, "h:MM A" ) - Time2Num("8:00 AM", "h:MM A" ) ) + ( Time2Num("5:00 PM", "h:MM A" ) - Time2Num(ToTime.formattedValue, "h:MM A" ) ) ) / (1000 * 60 * 60)<BR /><BR /> else <BR /><BR /> var PartialDayHours = ((Time2Num(FromTime.formattedValue, "h:MM A" ) - Time2Num("8:00 AM", "h:MM A" ) ) + ( Time2Num("5:00 PM", "h:MM A" ) - Time2Num(ToTime.formattedValue, "h:MM A" ) ) ) / (1000 * 60 * 60)<BR /><BR /> Total_Hours = 8 + 8 * ( Date2Num(ToDate, "YYYY-MM-DD") - Date2Num(FromDate, "YYYY-MM-DD") ) - PartialDayHours<BR /><BR /> endif<BR /><BR />endif<BR /><BR /><BR /><BR />Hope this saves somebody else some time...<BR /></BODY></HTML>Wed, 11 Feb 2009 19:20:27 GMT2009-02-11T19:20:27ZMath calculation problem! - Where is the help? ? ?
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64977#M22687
<HTML><HEAD></HEAD><BODY>I posted the message below hoping someone would be able to help - so far nothing!<BR /><BR /><BR /><BR />For sure there must be someone out there that can open the designer, create three numeric boxes, set the objects to be time oriented only, and the last box having the appropriate Java script or FormCalc script to have it show the difference in time.<BR /><BR /><BR /><BR />The script I show below works just great - accept as noted. WHY? What modifications do I need to make to have it work 100% of the time?<BR /><BR /><BR /><BR /><<<< below is the orginal posting on the forum >>>>>>>>>> <BR /><BR /><BR /><BR />The following Java script is entered in as the "total time" calculation formula <BR /><BR /><BR /><BR />"this.rawValue = endingTime.rawValue - beginningTime.rawValue" however when the following times are inserted the calculation accuracy fails. <BR /><BR /><BR /><BR />beginning time: 1430 <BR /><BR />ending time: 1700 <BR /><BR /><BR /><BR />the total time becomes 2:70 rather than 2:30. <BR /><BR /><BR /><BR />The reason seems to be the time format in PM mode is reading as a numeric formula rather than a time formula. Therefore, the subtraction is standard borrowing and carrying (1700 becomes 1600 + 100 + 0) rather than time (1700 becomes 1600 + 60). <BR /><BR /><BR /><BR />Does anyone have a solution? <BR /><BR /><BR /><BR />I have also tried resolving the issue using "FormCalc" but with no success <BR /><BR /><BR /><BR />Please help! <BR /><BR /><BR /><BR />thanks, <BR /><BR /><BR /><BR />tom<BR /></BODY></HTML>Fri, 11 Apr 2008 16:17:20 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64977#M226872008-04-11T16:17:20ZRe: Math calculation problem! - Where is the help? ? ?
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64978#M22688
<HTML><HEAD></HEAD><BODY>ok well friend your problem is with the way things are setup you cant just subtract a number and expect it to work in time format.<BR /></BODY></HTML>Fri, 18 Apr 2008 14:58:07 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64978#M226882008-04-18T14:58:07ZRe: Math calculation problem! - Where is the help? ? ?
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64979#M22689
<HTML><HEAD></HEAD><BODY>the accuracy is tottaly correct 1700 -1430 is 270 it is that simple however what your trying to do is subtract the milliseconds of one time from another and convert it back into that many milliseconds divided up into hours and minutes. So calm down and get the formcal refrence manual to help it is poorly written but it is a starting point.<BR /><BR />I think you want to do this set both of the fields startDate and EndDate to time/date fields this way you can lock the way information is entered set the display validation and binding patteren to HH:MM then set the binding tab to time from here your final box can be a text field or a date field doesnt matter so much then the easiest way to do this in Livecycle is to use form calc on the total time field<BR /><BR />set the script to formcalc and place it under the calculation event.<BR /><BR />if(startDate.isNull or endDate.isNull) \\ keep calculation clean<BR /><BR />then<BR /><BR />$ = 1 \\incase used with another calculation no errors<BR /><BR />else<BR /><BR />$=Time2Num(startDate.formattedValue, "HH:MM")-Time2Num(endDate.formattedValue, "HH:MM")<BR /><BR />endif<BR /><BR />you may have to do some tweaking to get the number that comes out as the format you want but this should lead you down the right path the Time2Num can be reversed using Num2Time also<BR /><BR />good luck<BR /></BODY></HTML>Fri, 18 Apr 2008 15:13:04 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64979#M226892008-04-18T15:13:04ZRe: Math calculation problem! - Where is the help? ? ?
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64980#M22690
<HTML><HEAD></HEAD><BODY>This solution almost worked.<BR /><BR /><BR /><BR />I had to make the following changes and it finally worked.<BR /><BR /><BR /><BR />I put what Puta Eka advised: <BR /><BR /><BR /><BR />if(startDate.isNull or endDate.isNull) <BR /><BR />then <BR /><BR />$ = 0<BR /><BR />else <BR /><BR />$=Time2Num(startDate.formattedValue, "HH:MM")-Time2Num(endDate.formattedValue, "HH:MM") <BR /><BR />endif <BR /><BR /><BR /><BR />in the calculation of a "hidden" date/time standard object.<BR /><BR /><BR /><BR />Then in the "shown" date/time object I added the following calculation script.<BR /><BR /><BR /><BR />$= form1.#subform1.difference / (60 * 60 * 1000)<BR /><BR /><BR /><BR />I tried putting the (60 * 60 * 1000) in with the formula from Puta Eka, but it just wouldn't work.<BR /><BR /><BR /><BR />Anyway, between his kind and considerate help and what I did, that problem was solved.<BR /><BR /><BR /><BR />On to the next problem!<BR /><BR /><BR /><BR /><span class="lia-unicode-emoji" title=":slightly_smiling_face:">ðŸ™‚</span><BR /></BODY></HTML>Wed, 23 Apr 2008 01:18:56 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64980#M226902008-04-23T01:18:56ZRe: Math calculation problem! - Where is the help? ? ?
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64981#M22691
<HTML><HEAD></HEAD><BODY>I had a lot of trouble with this too, thanks for the help. My solution also adds days for a leave form. The key for me was using the .formattedValue attribute and making sure the binding and value types for the time fields matched "HH:MM". My edit and display formats were "h:MM A".<BR /><BR /><BR /><BR />on the exit event:<BR /><BR /><BR /><BR />if ( HasValue(FromDate) and HasValue(ToDate) and HasValue(FromTime) and HasValue(ToTime) ) then<BR /><BR /> if ( FromDate == ToDate ) then<BR /><BR /> Total_Hours = 8 - ((Time2Num(FromTime.formattedValue, "h:MM A" ) - Time2Num("8:00 AM", "h:MM A" ) ) + ( Time2Num("5:00 PM", "h:MM A" ) - Time2Num(ToTime.formattedValue, "h:MM A" ) ) ) / (1000 * 60 * 60)<BR /><BR /> else <BR /><BR /> var PartialDayHours = ((Time2Num(FromTime.formattedValue, "h:MM A" ) - Time2Num("8:00 AM", "h:MM A" ) ) + ( Time2Num("5:00 PM", "h:MM A" ) - Time2Num(ToTime.formattedValue, "h:MM A" ) ) ) / (1000 * 60 * 60)<BR /><BR /> Total_Hours = 8 + 8 * ( Date2Num(ToDate, "YYYY-MM-DD") - Date2Num(FromDate, "YYYY-MM-DD") ) - PartialDayHours<BR /><BR /> endif<BR /><BR />endif<BR /><BR /><BR /><BR />Hope this saves somebody else some time...<BR /></BODY></HTML>Wed, 11 Feb 2009 19:20:27 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64981#M226912009-02-11T19:20:27ZRe: Math calculation problem! - Where is the help? ? ?
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64982#M22692
<HTML><HEAD></HEAD><BODY>For many calculations, you need to check that you have the necessary fileds before calculating. For date and time calculations, the exact format of the data string is needed to correctly convert the date. For example Jan 3, 2009 can be written like "01/03/2009" ("MM/DD/YYYY" or 03/01/2009 ("DD/MM/YYYY") and using the wrong formatting string will get you the values for Mar 1, 2009.<BR /></BODY></HTML>Wed, 11 Feb 2009 20:20:14 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-discussions/math-calculation-problem-where-is-the-help/m-p/64982#M22692gkaiseril2009-02-11T20:20:14Z