Time Period - Date Calculations

Comments

10 comments

  • Rainer Grabowski

    Hi Warren,

    assuming you have these 2 fields:
    Date field (move in date)
    Number field (number of month)
    you get the end date in the calculation field with this:

    moment(@date field).add(@number field,"months").toDate()

    For the mortgage period: If the period is always fixed to 20 months:

    moment(@date field).add(20,"month").toDate()

    Rainer

    1
    Comment actions Permalink
  • Warren Jonas

    Thanks for the help Rainer - that worked!

    0
    Comment actions Permalink
  • Luke Holcomb

    Ranier,

    I am using this for a similar calculation and I'm getting 

    Script error: TypeError: undefined is not a function

     

    any help? 

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Luke,

    please share a screenshot of your calculation field.

    Rainer

    0
    Comment actions Permalink
  • RAUL GONZALEZ

    hello, i have a help desk application under podio and i included a field to calculate the number of tickets issued like this:  @All of Ticket Number.length

    i have a different field with the date the customer agreement ends and i want to include the javascript in order for me to receive only the tickets issued from the ending date and a year back, please help me to define the java script

    Each customer agrrement is valid for one year so i want to have the tickets issued under this period

    0
    Comment actions Permalink
  • RAUL GONZALEZ

    any help will be great appreciated

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hello Raul,

    this should work:

    var start = moment(@date agreement ends).subtract(1,"year").unix();
    var ticketDates = @All of Ticket Date;
    var sum = 0;
    for(var i = 0; i < ticketDates.length; i++){
       if(moment(ticketDates[i]).unix() >= start){
         sum +=1;
      }
    };
    sum

    That returns the number of tickets since Agreement end date minus 1 year. 

    Rainer

     

    0
    Comment actions Permalink
  • RAUL GONZALEZ

    thanks Rainer, i wrote down:                                                                                                                                                                        var start = moment(@Deadline).subtract(1,"year").unix();
    var ticketDates = @All of Ticket Number.length;
    var sum = 0;
    for(var i = 0; i < ticketDates.length; i++){
    if(moment(ticketDates[i]).unix() >= start){
    sum +=1;
    }
    };  

     

    but it only returns 1

    i change @all of tickets date for ,@all of ticket number.length due to it adds all the tickets numbers, is this correct?

    0
    Comment actions Permalink
  • Rainer Grabowski

    My code compares the start date with a date field in the tickets, .unix() returns the timestamp of that date.
    So you can't use the field Ticket Number (I think it's not a date field), that doesn't make any sense. You must use a date field from your ticket app. 
    The date field must be referenced with

    @all of name of the date field

    (nothing behind it)
    The Ticket Number could be used if the number includes the date in number format, e.g. if the ticket number is structured like
    20180913123 (where the first 8 digits are YYYYMMDD and represent the date the ticket is submitted). 

    If you don't have a date field in your Ticket app you can add a calculation field with @created on and then reference that calculation field with @all of 

    Rainer

    1
    Comment actions Permalink
  • RAUL GONZALEZ

    many thanks Reiner, i will look into this. thanks again for your help

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk