Calculate how many Days left between Date and Current Date

Answered

Comments

6 comments

  • Rainer Grabowski (FVM)

    Hi,

    the computer time you can't get (maybe via the API, you have to ask a developer for that). You can calculate the current time e.g. with momentjs (a Javascript library). So
    @enddate.diff(moment(), 'days')
    shows the number of days between your enddate and current day (more about moemntjs: http://momentjs.com/docs/ )

    But the problem is, that a calculation field will only be updated when one of the values of the calculation changes. So if you use moment() in your calculation it shows that number of days which is actual at the moment of the last change of your enddate.

    So for a real count down you need a date field, that changes daily. I know two workarounds. For the first you need the Podio Extension Globiflow. Then create an extra date field only for daily updates and let it be updated by Globiflow on midnight. A possible calculation formula with this field could be:

    var end = moment(@enddateField);
    var cur = moment(@extraDateField);
    
    end.diff(cur, 'days') 
    

    The second workaround maybe sounds a bit funny: You need an own app (e.g. called "Timer") with only one item "Current Date" with only one date field "Current day". This date you have to update daily manually (assigns a daily task to yourself or let it be done by Globiflow).This item must be connected to all items in the app where you need the count down. For that you have to create a relationship field in this app with a relation to the app "Timer". In every item you have to pick the relation to the item "Current Date" (if you are a Plus or Premium user, Podio Advanced Workflows can do that for you automatically). The calculation for the number of days would look like:

    var end = moment(@enddateField);
    var cur = moment(@min of Currend Day);
    
    end.diff(cur, 'days') 
    

    Rainer

    1
    Comment actions Permalink
  • Rik, Ching-Fang Chuang

    Thank you for the answer.
    I found a way too.

    moment(@Deadline).diff(moment(),'days');

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    The formula is ok for getting the diffference, but it won't work as count down. You'll have the same number of days tomorrow as today.

    0
    Comment actions Permalink
  • Rik, Ching-Fang Chuang

    I see. Thank you so much.

    0
    Comment actions Permalink
  • Mark Cannon

    What about the following podio calculation (using javascript Date.now())? Will the now() value not be updated at each moment?

    Math.floor((@Appointment (City's  timezone)).valueOf() / (1000 * 60 * 60 * 24)) - Math.floor((Date.now() - 7 * (1000 * 60 * 60)) / (1000 * 60 * 60 * 24))

    0
    Comment actions Permalink
  • 0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk