Calculation a date in the future
AnsweredHi,
I want to calculate a date in my app. There is a date entered (choose date by klick in the calender). Now I want to summate 6 months and the result should be another date.
For example:
I enter 01.01.15 (dd.mm.yy) in a datefield. The function calculate should now summit 6 months and the result should be 01.07.15 (dd.mm.yy) shown in another datefield.
How to enter this calculation? I´ve tried some things like "@datafield + 6month" etc. but without a result.
Regards
Kai
-
Hi Kai,
try:moment(@dateField).add(6, 'months').toDate();
Cheers,
Rainer
rg@delos-consulting.com -
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,
-
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 -
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() : ""
-
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 betoAdd = num == "Month-to-month" ? 1 : num == "Annual" ? 12 : 60;
num != null ? moment(date).add(toAdd,'months').toDate() : ""Rainer
-
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 aI'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
-
"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.phpRainer
Please sign in to leave a comment.
Comments
18 comments