0

Date in Formula

I have tried this formula without success:

If today() - Date > 364 then "Long" else "Short"

No matter what the value of Date the formula always returns the result "Short".

What am I doing incorrectly?  Is there any source in the manual or elsewhere to assist a novice in writing formulas?

1 reply

null
    • Fred
    • 3 yrs ago
    • Reported - view

    Hi Jon -

     

    Welcome to world of poorly written manuals of Ninox.

     

    What you should write is:

     

    if days(Date, today()) > 365 then
    "long"
    else
    "short"
    end

     

    We use a special function called "days" where it finds the difference in days between your start date and end date. The most important thing is that Ninox returns a simple number.

     

    As I am still learning Ninox, to troubleshoot formulas, I've started breaking down the parts of a formula to see what kind of data is created. In your case, try creating another formula field (call it test1) and put the start of your formula in there:

     

    today() - Date

     

    You will see that Ninox does not return a number. Ninox is taking todays date, in milliseconds since UNIX epoch, and subtracts your Date field, in milliseconds since UNIX epoch, and then converts the difference into text that is readable to humans.

     

    Screen Shot 2021-05-31 at 08.47.58

     

    So then you will see that you can't just subtract date fields.

     

    You can get the special date functions here:

    https://ninox.com/en/manual/calculations/reference-of-functions-and-language

     

    Scroll down far to find them.

     

    You can view the free Nioxus videos on YouTube to get a better understanding of Ninox and how to write code in Ninox. Plus learn a lot of other things.

     

    Good luck.

Content aside

  • 3 yrs agoLast active
  • 1Replies
  • 340Views