Trying to add @# (Numerical # Field) + @Date (Date Format Field)

Comments

12 comments

  • Michael Kagan

    Hey Brandon,

    I was looking to do something similar and from another post in the community ("Calculating a new date +/- X days"), I finally got it to work for me with the following coding (after deleting the calculation field and creating a new one, another tip from that post):

    var zover = @Start Date
    zover.setDate(@Start Date.getDate() + @Duration);
    zover;

    I created a variable (zover) to hold the original date (@start date) and then replaced the original date with the calculated date in zover. @duration was a field I created in the template where I entered the amount of days I wanted to add. By the way, I tested the code with a specific number instead of @duration and that worked, too.

    the getDate() function apparently returns the day of the month and the setdate() function sets the day of the month of whatever month the object is already holding, in my case it was the start date's month that I placed into the over variable zover.

    There are probably a number of different ways to approach this issue, so if you find another way in your search please post it back here.

    Full disclosure: I am not a programmer so I am not sure my explanation is correct and, in any case, I would not be able to answer any technical or syntax questions as to why this worked. Those questions would be better asked of others like the ones from the other discussion thread.

    Happy to discuss Podio implementations (or anything else)!

    Good luck.

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    HI,

    as an alternative you can use the moment js-library which is supported by Podio. Momentjs is very helpful for calculations http://momentjs.com/docs/

    var date = @your date field;
    var DueDate = moment(date).add(30, "days").format("YYYY-MM-DD");
    DueDate

    or if you want to use a number field for the # of days

    var date = @your date field;
    var num = @your number field ;
    var DueDate = moment(date).add(num, "days").format("YYYY-MM-DD");
    DueDate

    2
    Comment actions Permalink
  • Michael Kagan

    Thanks! @Rainer Grabowski

    0
    Comment actions Permalink
  • Brandon Dente

    @Rainer Grabowski I attempted using moment js-library script but unfortunately it kicked back a date that was 2 years 11 months and 10 days from the @your date field when @your number field=30 days.

    2016-09-20

    Although going with the specified amount of days script and in your case was 30 days, was successful

    2014-10-31

    But this is a start because this is the closest to a date in the future that I have been able to get, so were getting warmer... I'm trying to auto calculate the last day for returns on all purchases and because different stores have different return policies, unfortunately even though the script was successful, I need something more like the script that allowed to specify # of days

    0
    Comment actions Permalink
  • Brandon Dente

    I apologize, it wasn't a # field but a time/days field and thats why it wasn't calculated correctly...So I take it back, the 2nd script works perfectly and displays the date just fine!! I've changed my app to reflect the field as a # field but just curious would there be a way to use the time/days field? ie: 30 days

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Hi Brandon,

    I think you mean a duration field. Sure you can use it.
    Try instead of var num = @your number field

    var num = @your duration field / 24 // 24 hours per day

    Rainer
    rg@delos-consulting.com

    0
    Comment actions Permalink
  • Justin Baeder

    Rainer, thanks so much for this example! I used:
    var date = @your date field;
    var DueDate = moment(date).subtract(9, "days").format("YYYY-MM-DD");
    DueDate
    To return the date for my field that means "When do I need to start doing X, based on Y event, if X always needs to happen 9 days before Y?"

    Worked great!

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Hi Justin,

    yes, in this case X always is 9 days before Y.

    You can modify the number of days with a variable. Let's say, 9 days is your standard time span (X-9). But you want to have the possibilty to be flexibel.

    Add a number field " Time Span".
    Change your script:

    var date = @your date field;
    var spanNumber = @your number field;
    var spanTime = spanNumber != "" ? spanNumber : 9  
    

    // read it as: when number field is not empty then take the value of the number field else take 9 for the following calculation

    var DueDate = moment(date).subtract(spanTime, "days").format("YYYY-MM-DD");
    

    DueDate

    0
    Comment actions Permalink
  • Susie Atwood

    Debbie. Just wanted to let you know that I won't be in tomorrow. I have a field trip that I had forgotten about. I can make up time Friday if that would help. 

    0
    Comment actions Permalink
  • Sinan S. Celebci

    var date=@Received Date
    var DueDate=moment(date).add(30,"days").format("YYYY-MM-DD")
    moment(DueDate).toDate()

     

    This formula back the result with date not the number.

    By this way , I can add the result to the Calendar.

    0
    Comment actions Permalink
  • Gus H.

    On this line, how about getting a reminder to wish someone a Happy B-D? Any way we can do better than what I'm getting here? This person was born on 5/12/89. Thank you.

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Gus, 
    I recommend to read this thread to understand the general issue. In the same thread I've described how I solve it for my clients with a workaround. With this workaround you can create automatically a new reminder for every year. 

    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk