Trying to add @# (Numerical # Field) + @Date (Date Format Field)
example: 12/01/2014 (the day entered in the field that item was purchased) + 30 (the days item can be returned to store)
Wish js was easy as just @# + @Date but obviously need to get @# into Date format so could use some help on this. The closest I could get was 7 years in the future but at least it was an actual Date ;)
-
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.
-
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");
DueDateor 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 -
@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
-
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
-
Hi Brandon,
I think you mean a duration field. Sure you can use it.
Try instead of var num = @your number fieldvar num = @your duration field / 24
// 24 hours per dayRainer
rg@delos-consulting.com -
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!
-
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
-
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
Please sign in to leave a comment.
Comments
12 comments