Nanoflow daysbetween function

0
Hi  I am trying to calculate days between two dates(current datetime and datetime value from object) in nanoflow.  I see that daysbetween function is not available in nanoflow. Is there a way to calculate daysbetween in offline mode?   Thanks
asked
2 answers
2

If the dates are created when online you might store the unix time variant of the dates in separate fields and then substract and divide to calculate the number of days. If however the dates are being entered in offline mode and you need the difference in days you have quite a task ahead of you. With string manipulations (tostring and substring functions) you can find the month, day and year for the dates. You can transform the integer data into sort of a unix time in days by first determining the amount of days since the start of the year, Then determin the amount of days between the start of the year and 1-1-1970, to accomodate for multiple years (but not before 1970!) and then substract the 2 integer to find the days between the 2 dates. If the dates are in the same year only calculate back to the beginning of the year.

Quite a task as said as you'll need to take into account the leapyears as well, see below for the logic to determine the leapyear:

  1. If the year is evenly divisible by 4, go to step 2. ...
  2. If the year is evenly divisible by 100, go to step 3. ...
  3. If the year is evenly divisible by 400, go to step 4. ...
  4. The year is a leap year (it has 366 days).
  5. The year is not a leap year (it has 365 days).
answered
3

Hi

We've had a similar problem and actually build a custom widget to do the computation.

The widget would write the result in a temporary attribute and then you can use it in follow-up actions.

FillCurrentDateTimeString Widget (GitHub)

regards Fabian

answered