Post

4 followers Follow
0
Avatar

Calculated Field to Take Created On Date and Make Next Monday

Hey Podio! In the advanced Workflow, we can make a due date of 'Next Monday', but how do we make a calculated field in an app item to take the created on date and set to next Monday?

Nathan Velasquez

Please sign in to leave a comment.

11 comments

0
Avatar

Not looking to change the created on date, just looking for a calculation to set the date to Next Monday "Mon MONTH DAY YEAR"

Nathan Velasquez 0 votes
1
Avatar

Hi Nathan,

you have two options in which format the result is shown:
1. as a date field (which can be used in calendars) or
2. as a text string

As date field:

var cOn = @createdOn;  // the created on date
var cOnNum = moment(cOn).isoWeekday(); // gets the weekday number (in ISO-Format Mon = 1, Sun = 7)
var cOnDiff = 8-cOnN ; // calculates how many days must be added to cOn for getting next Monday

moment(cOn).add(cOnDiff, 'd').toDate() //displays the result as a date

If you need a text string change only the last line to:

moment(cOn).add(cOnDiff, 'd').format ('ddd MM-DD-YYYY') //displays the result as a text string like
 "Mon 02-21-2015" if the cOn is between Feb, Mon 14th and Feb. Sun 20th

Rainer
rg@delos-consulting.com

Rainer Grabowski (FVM) 1 vote
0
Avatar

Looks good Rainer!. Thanks again! I will have to test on Monday again. I just want to be sure all items with a creation date of any Monday, still always return the date of the following Monday.

Nathan Velasquez 0 votes
0
Avatar

Hi Nathan,

if only items created on a Monday should always return the date of the following Monday but items in the same app created on any other weekday should keep their date change var cOnDiff:

var cOnDiff = cOnNum == 1 ? 7 : 0
Rainer Grabowski (FVM) 0 votes
0
Avatar

That's good to know, but I want a default date of Next Monday regardless of day of the week the item was created on. I was just curious about if an item was created on Monday, if the value of the field would return Monday ( the creation date ) or Monday ( one week after ).

I can see this possibly changing to, if the created on date matched these days of the week Thurs, Fri, Sat, or Sun, to return 2 Mondays after. .

Nathan Velasquez 0 votes
0
Avatar

In regards to above, created on dated on dates of Mon, Tues, Wed, would use the same script to return the date of next Monday.

Nathan Velasquez 0 votes
0
Avatar

The first script will always return the date of next Monday, regardless on which weekday the item is created.
created on: -> returns:
Monday, Feb 16th -> next Monday, Feb, 23rd
Tuesday, Feb 17th -> next Monday, Feb, 23rd
...
Sunday, Feb 22nd -> next Monday, Feb, 23rd

The second script (var cOnDiff = cOnNum == 1 ? 7 : 0) returns next Monday only for items created on a Monday
created on: -> returns:
Monday, Feb 16th -> next Monday, Feb, 23rd
Tuesday, Feb 17th -> same Tuesday, Feb 17th
...
Sunday, Feb 22nd -> same Sunday, Feb 22nd
Monday, Feb 23th -> next Monday,Mar, 2nd
Tuesday, Feb 24th -> same Tuesday, Feb 24th

If you want to return every created on date plus one week then you need only this line in your calculation field:

moment(@created on).add(7, 'd').toDate()

Result:
Monday, Feb 16th -> next Monday, Feb, 23rd
Tuesday, Feb 17th -> next Tuesday, Feb 24th
...
Sunday, Feb 22nd -> next Sunday, Mar 1st
Monday, Feb 23th -> next Monday,Mar, 2nd
Tuesday, Feb 24th -> nextTuesday, Mar 3rd

Rainer

Rainer Grabowski (FVM) 0 votes
0
Avatar

Hej, @createdOn doesn't work for me. Podio says "unexpected token illegal". What did I do wrong?

Jan Richter 0 votes
0
Avatar

Got it! It depends on language. In german it's not "@createdOn" but "@Erstellt von".

Jan Richter 0 votes