Counting days between dates
AnsweredHello, I am trying to count between different dates and the current date. I will show you what I need. (date 2 is always higher than date 1 and date 3 is always higher than date 2)
Date 1 (required field)
Date 2
Date 3
Calculation 1:
If date 2 & 3 are empty: show the difference between date 1 and the current date.
If date 2 is empty and 3 is filled: show the difference between date 1 and 3.
If date 2 if filled: show the difference between date 1 and date 2.
Calculation 2:
If date 2 is filled and date 3 empty: show the difference between date 2 and current date.
If date 2 and 3 are filled: show difference between date 2 and 3
If date 2 is empty: show 0
Problems:
I understand the if statement a little bit, i got it working with two elements, but now i have three.
I don't know how to calculate with the current date.
What i have so far:
Calculation 1:
if (@date1 != null) {
(@date 2 - @date1) / 86400000 }
else if (@date 3 != null) {
(@date3 - @date1) / 86400000 }
else { ( getDate() - @date1) / 86400000}
Calculation 2:
if (@date2 == null) {
0 }
else if (@date3 != null ) {
(@date3 - @date2) / 86400000}
else { ( getDate() - @date2) / 86400000}
Sometimes things works, but i don't understand why so please help me.
-
I fixt it myself. Whoa after a week trying i asked, and a few hours later it works whoehoe
This is the solution:
calculation 1:
if ( Date2 != null) { ( Date2 - Date1 ) / 86400000} else if (Date3 != null) { ( Date3 - Date1 ) / 86400000} else { (moment() - Date1 ) / 86400000 } ;Calculation 2:
if ( Date2 == null ) {0} else if ( Date3 == null ) { (moment() - Date2) / 86400000 } else { ( Date3 - Date2 ) / 86400000 } ;
-
I would love help with something similar I can't find a solution to yet. Much more basic. I have a service date listed in the app. I want a calculation field to calculate how many days until that service date so that I can use that result for other operations. Think I could get your help for that?
Please sign in to leave a comment.
Comments
2 comments