Calculation a date in the future

Answered

Comments

18 comments

  • Rainer Grabowski (FVM)

    Hi Kai,
    try: moment(@dateField).add(6, 'months').toDate();

    Cheers,
    Rainer
    rg@delos-consulting.com

    1
    Comment actions Permalink
  • Kai Rauprich

    Hi Rainer,

    thank you for your help. It looks very good right now but there ist another little thing now: The result is date plus the time. The result should be just the date without the time.

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Hi Kai,

    go to the template creator, click that little arrow besides the icon of your calculation field - and you'll get a menu where you can deactivate "time"

    0
    Comment actions Permalink
  • Kai Rauprich

    Wonderful! Thank you very much for your help :)

    Regards
    Kai

    0
    Comment actions Permalink
  • Hélène Hagnéré

    Rainer (or equally knowledgeable Podio users :)), do you how we can do this but not with a fixed amount of time but thanks to a number field?

    I would like to have a "Renewal date" (end result of the calculation) that would equal a "Billing cycle" (number field that can be 3, 6 or 12 for quarterly, bi-yearly, yearly contracts) added to the Date Created on of the item in the General Properties of the app template.

    Thanks a million for the help,

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Hi Helene,

    this should work:

    var num = @your numberField;
    var date = @your dateField;

    ' moment(date).add(num, 'months').toDate();`

    If the contract entry has another indicator then the number field that shows if it is a quarterly, bi-yearly or yearly contract
    you can substitute the number field by a calculation field and use an IF-Condition (so you don't have tp type in the number):

    indicator == "what ever shows it is quarterly" ? 3 : indicator == "what ever shows it is bi-yearly" ? 6 : 12

    Hope it helps,
    Rainer

    1
    Comment actions Permalink
  • Kai Rauprich

    I have an additional question to this topic. When there is no data entered, the system shows always the date of "01.01.1970". Can i do something against that? When there is no data entered, this information should be empty.

    Thank you,
    Kai

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Hi Kai,

    @dateField != null ? moment(@dateField).add(6, 'months').toDate() : null
    

    read as: IF dateFied is not empty, than put in date + 6 month, else let the calculation field empty.
    If there are other values in your calculation field too, use : "" instead of :null.

    Rainer

    1
    Comment actions Permalink
  • Kai Rauprich

    Hi Rainer,

    and again thank you very much :)

    0
    Comment actions Permalink
  • Allen Moma

    HI Kai,

    I'm attempting to do create a data calculation as well. I believe that I have followed your instruction but not getting the results I'd hoped for.  What am I missing?

    thanks

    var num = @Lease Type;
    var date = @Move-in Date;

    num == "Month-to-month" ? 1 : num == "Annual" ? 12 : 60;

    num != null ? moment(date).add(num,'months').toDate() : ""

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hello Allen,

    you code looks ok. What doesn't work? Do you get any error notification in the preview? Is your calculation field a date type field?

    Rainer

    1
    Comment actions Permalink
  • Allen Moma

    I set the move-in date to 1 May 2017. Preview returns 4/30/2017

    Additionally, It doesn't matter which option I select M2M, Annual the date does not change in the Renewal Date field. 

    0
    Comment actions Permalink
  • Allen Moma

    Im not sure. How do you set the calculation field to "date"?

    0
    Comment actions Permalink
  • Rainer Grabowski

    If the date in the renewal date field is shown in the item (after saving the template) like a normal date field it is date type.
    A calculation field can be text, number or date type. The type is defined once you've saved it and it can't be changed. In the template builder, click that little triangle besides the icon of your calculation field, you'll get a menu where you can see which type it is: if date type you'll e.g. see an option to select if it should be shown in calendars, if number type you see some options for defining the decimals, if text type you have only 3 options (required, hidden if empty, always hidden).

    A tip: If you want it as a date field (which displays the result like a "normal" date field) enter in new field @created on and save the template. Now it's forever date type. 

    Here in the forum are several postings concerning the wrong date (04/30 instead 05/01), it depends on the fact that if you use moment() you lose your own time zone, your date is converted to UTC time. You can avoid that be adding your time zone (the same you have set in your Podio Accouint settings): moment(date).tz("Europe/Berlin") f.ex. is my timezone.

    And now I've seen the mistake in your code. Sorry, have missed it the first time:
    This line is wrong: num == "Month-to-month" ? 1 : num == "Annual" ? 12 : 60;
    Must be

    toAdd = num == "Month-to-month" ? 1 : num == "Annual" ? 12 : 60;
    num != null ? moment(date).add(toAdd,'months').toDate() : ""

    Rainer

    0
    Comment actions Permalink
  • Allen Moma

    Rainer,

    That worked, thank you!

    Is "toAdd" a built in function or a second variable that hold the results of "num"? 


    This agreement shall commence on 1 May 2017 and continue until 2017-06-01 00:00:00 as a

    I'm using the value in Renewal date in Globiflow to create a pdf form.  If I understand the process, it looks like I need to convert the UTC time back to  a normal date field.

    Is there a formatting instruction to do this?

    Allen

    0
    Comment actions Permalink
  • Allen Moma

    Failed to mention that the output is correct in the Podio template. 

    0
    Comment actions Permalink
  • Rainer Grabowski

    "toAdd" is only a var name, instead of "toAdd" you can also take "abc" or "howAreYou" or .... :)

    In Globiflow you have to format the date like: date("d F Y",strtotime([(item) Renewal Date])). More info you find in the Globiflow Help http://www.globiflow.com/help/php-calculation-examples.php

    Rainer

    0
    Comment actions Permalink
  • Allen Moma

    Thanks Rainer that did it.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk