Trying return a number on subtracting today's date from a given date in a field.

Comments

10 comments

  • Rainer Grabowski

    Hello Gunnar,

    the general calculation for it is:

    moment(@date field).diff(moment(),"days")

    But: There' isn't a real "Today"-value available in the calculation field. Today's date is represented by: moment(). But It won't change. It fetches only the moment you saved the calculation or the moment a variable (in your case @date field) changes.

    Means: If you create your field today (e.g.. June 15th) , it will have the right date But tomorrow (June, 16th) there will be the same (old) date. Only if the calculation is updated by a change in another variable in it (@date field) , it will change. For this issue see here  https://help.podio.com/hc/communities/public/questions/204569657-Definite-solution-for-today-handling-in-calculated-fields-days-since-days-until-countdown-incl-possible-solution

    There's only one workaround :
    1. Create an app  e.g. called "Timer" with a title field and a date field e.g. called "Today". Create one item only with the title e.g. "Today's date". In the date field enter the current date - you have to update this field every day. If you use  Globiflow it can be done automatically, if not you have to do it manually (or via the API, which needs some developer skills).
    2. Create a relationship field in the app where you want to calculate the difference  (make it a "required field") which points to the app Timer and link each contact to the item "Today's date".

    Then you can use a calculation like 

    moment(@date field).diff(moment(@max of Today),"days")

    For all of my Podio-clients I implement such a timer app. It's related to one or two central apps like Projects, Deliverables or employees/team member. These apps pull the today date into a calculation field (@max of today). Cause many other apps are related to one of central apps, all these apps have access to the today date and can use it for their calculations.

    Rainer
    rg@delos-consulting.com 

    1
    Comment actions Permalink
  • Stephen Sibley

    Hello Rainer, clever work around, thanks!

    The calculation Preview displays the expected value, but when i click DONE i'm getting this error "The type of result changed from text to number.".

    Any thoughts? 

    0
    Comment actions Permalink
  • Stephen Sibley

    cancel that, found your answer in another thread

    0
    Comment actions Permalink
  • Scott Anderson CCIM

     

    Perfect!  Thanks Rainer.  One tweak request... my end result comes up as a negative, "-10 days".  Is there a way to have it show as a positive number?  ie: "10 days".  Thank you!

    0
    Comment actions Permalink
  • Rainer Grabowski

    A simlpe way with Math.abs()

    var diff = moment(@date field).diff(moment(@max of Today),"days");
    Math.abs(diff)
    0
    Comment actions Permalink
  • James Perfect

    @rainer if I may ask, what is the Globiflow flow? I've been going through this thread, and through Globiflow, and am still thoroughly confused on that.

    Thank you for all your wonderful help and comments!

    0
    Comment actions Permalink
  • Rachel Gretton

    This is great thanks.

    One last question, I'm using this calculation:

    var diff = moment(@Due Date).diff(moment(@Max of Today),"days");
    Math.abs(diff)

    My result for example is '21:00' how can I change it to '21'

    Thanks in advance.

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Rachel,

    21:00 shouldn't be possible,the date diff function always returns a number. 
    Check the settings of the calculation field if it is number or date type. 
    You can also create an new calc field, copy your code into it but add as last line 1. Save the template, open it again and remove the 1. This way you can be sure that it is number type. 

    Rainer

    0
    Comment actions Permalink
  • Yuriy Gordiyenko

    Hello,

    How to convert this to months

    0
    Comment actions Permalink
  • Sara Christensen

    I created the Timer App. I created the Today item with Today's date populated in the date field. In App B, I associated all items with this timer item. Any clues as to why my field doesn't show up when I do "@max of..." in the calculation field in App B?

    -1
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk