Post

5 followers Follow
0
Avatar

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

 I have a date field ( date of a foreclosure sale) and are trying to add a calculation field show how many days are left to that auction sale date. Thanks

Gunnar Jonsson VP

Please sign in to leave a comment.

5 comments

0
Avatar

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 

Rainer Grabowski 0 votes
0
Avatar

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? 

Stephen Sibley 0 votes
0
Avatar

 

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!

Scott Anderson CCIM 0 votes
0
Avatar

A simlpe way with Math.abs()

var diff = moment(@date field).diff(moment(@max of Today),"days");
Math.abs(diff)
Rainer Grabowski 0 votes