Question Calculate only if both variables exist in Adobe LiveCycle Questions
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/calculate-only-if-both-variables-exist/qaq-p/144637
<HTML><HEAD></HEAD><BODY><P></P><P>I have searched high and low for a solution and have yet to find one that works for my calculation.</P><P></P><P>Here is the code I currently have in the field doing the calculation:</P><P></P><P></P><P></P><P>var oneDay = 24*60*60*1000;</P><P></P><P>var firstDate = new Date(rentalbegin.rawValue);</P><P>var secondDate = new Date(rentalend.rawValue);</P><P>Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));</P><P></P><P></P><P></P><P>This calculates the difference between two dates to determins the total amount of rental days. The problem is, when only one variable is entered the calculation reads the empty field as 0 and calculates the difference. I need something that says 'if rentalend.rawValue == 0 then event.value = "" '. I appreciate any help in this matter.</P><P></P><P>Thank you,</P><P>Trey</P></BODY></HTML>Tue, 31 May 2011 14:36:47 GMTtreysgrn2011-05-31T14:36:47ZCalculate only if both variables exist
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/calculate-only-if-both-variables-exist/qaq-p/144637
<HTML><HEAD></HEAD><BODY><P></P><P>I have searched high and low for a solution and have yet to find one that works for my calculation.</P><P></P><P>Here is the code I currently have in the field doing the calculation:</P><P></P><P></P><P></P><P>var oneDay = 24*60*60*1000;</P><P></P><P>var firstDate = new Date(rentalbegin.rawValue);</P><P>var secondDate = new Date(rentalend.rawValue);</P><P>Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));</P><P></P><P></P><P></P><P>This calculates the difference between two dates to determins the total amount of rental days. The problem is, when only one variable is entered the calculation reads the empty field as 0 and calculates the difference. I need something that says 'if rentalend.rawValue == 0 then event.value = "" '. I appreciate any help in this matter.</P><P></P><P>Thank you,</P><P>Trey</P></BODY></HTML>Tue, 31 May 2011 14:36:47 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/calculate-only-if-both-variables-exist/qaq-p/144637treysgrn2011-05-31T14:36:47ZRe: Calculate only if both variables exist
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/re-calculate-only-if-both-variables-exist/qaq-p/144638/comment-id/76032#M76032
<HTML><HEAD></HEAD><BODY><P>You need to use the 'if' statement to see if a date has been entered for both dates and then perform the calculation or clear the field.</P><P></P><P>var oneDay = 24*60*60*1000;</P><P></P><P>if(rentalbegin.rawValue != "" & rentalend.rawValue != "") {</P><P> var firstDate = new Date(rentalbegin.rawValue);</P><P> var secondDate = new Date(rentalend.rawValue);</P><P> Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));</P><P>} else {</P><P>"";</P><P>}</P><P></P><P>You might find FormCalc an easier language to perform this calculation as the 'Date2Num' function returns the number of days since the Epoch date and not the number of milliseconds and has the "HasValue()" function.</P></BODY></HTML>Tue, 31 May 2011 16:09:58 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/re-calculate-only-if-both-variables-exist/qaq-p/144638/comment-id/76032#M76032gkaiseril2011-05-31T16:09:58ZRe: Calculate only if both variables exist
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/re-calculate-only-if-both-variables-exist/qaq-p/144639/comment-id/76033#M76033
<HTML><HEAD></HEAD><BODY><P>What would be the formcalc equivalent code? </P></BODY></HTML>Tue, 31 May 2011 17:06:08 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/re-calculate-only-if-both-variables-exist/qaq-p/144639/comment-id/76033#M76033treysgrn2011-05-31T17:06:08ZRe: Calculate only if both variables exist
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/re-calculate-only-if-both-variables-exist/qaq-p/144640/comment-id/76034#M76034
<HTML><HEAD></HEAD><BODY><P>Also, the above if else statement still produces the same effect. </P></BODY></HTML>Tue, 31 May 2011 18:26:00 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/re-calculate-only-if-both-variables-exist/qaq-p/144640/comment-id/76034#M76034treysgrn2011-05-31T18:26:00ZRe: Calculate only if both variables exist
https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/re-calculate-only-if-both-variables-exist/qaq-p/144641/comment-id/76035#M76035
<HTML><HEAD></HEAD><BODY><P>I fixed the statement by figuring out what the value of the rentalend field was. In the code it was if rentalend.rawValue != "". Well the value was being calculated somewhere or else I wouldnt have been getting a result. So I changed the code to reflect " if(rentalend.rawValue > "1") " and it worked! Thank you so much!</P><P></P><P>Here is the full working code for those that need it as well.</P><P></P><P></P><P></P><P>var oneDay = 24*60*60*1000;</P><P></P><P>if(rentalend.rawValue > "1") {</P><P></P><P>var firstDate = new Date(rentalbegin.rawValue);</P><P>var secondDate = new Date(rentalend.rawValue);</P><P>Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));</P><P>}</P><P>else {</P><P>"";</P><P>}</P><DIV> </DIV></BODY></HTML>Tue, 31 May 2011 18:36:54 GMThttps://experienceleaguecommunities.adobe.com/t5/adobe-livecycle-questions/re-calculate-only-if-both-variables-exist/qaq-p/144641/comment-id/76035#M76035treysgrn2011-05-31T18:36:54Z