cancel
Showing results for 
Search instead for 
Did you mean: 

Issue while adding days to date field in mapper

amardeep2021
New Contributor III

Hi,

I have a scenario where I am trying to increment a date field by 7 days in loop till it reaches another date value. I see data type as date for the field I am working, still while using plusDays(7) function I am getting error. I couldn’t date.parse() as it’s already a date field. I can’t convert to string as I need to add days to the same field in loop. Does anyone know how to overcome this issue? Please advise.

PFA of screenshot from mapper snap.

Regards,
Amar.
Screen Shot 2022-01-19 at 3.39.58 PM

9 REPLIES 9

May I ask why do you need the loop when you already know the desired date? If you need all of the dates between two dates with step = 7 ( Ex.: 2022.01.01,…08,…15,…22,2021.01.29), than you can achieve this with the following expression:

sl.range(0,(($endDate-$startDate)/86400000)+1).filter(x=>x%7==0).map(y=>$startDate.plusDays(y))

Here is a sample pipeline as well:

Date Range Step 7_2022_01_20.slp (3.8 KB)

I hope you’ll find this helpful.

amardeep2021
New Contributor III

Thanks for your response Bojan.

Scenario is to check first row of the weekof < post_prod_support7. If it’s true I need to add 7 days to weekof and append second row with no change in other columns.
Next is to check second row of the weekof < post_prod_support7. If it’s true I need to add 7 days to weekof and append third row with no change in other columns.
Next is to check third row of the weekof < post_prod_support7. If it’s true I need to add 7 days to weekof and append forth row with no change in other columns.
.
.
.
likewise it has to add records with only change in weekof field value alone, till above condition is false.

I tried the expression you shared earlier and getting a different issue. PFA. Any tip will be helpful.

Regards,
Amar.
Screen Shot 2022-01-20 at 3.01.08 PM

Screen Shot 2022-01-20 at 3.01.08 PM

These are Date types, as we said before, you have to parse them, than do the operations. Try this:

sl.range(0,((Date.parse($post_prod_support7)-Date.parse($weekof))/86400000)+1).filter(x=>x%7==0).map(y=>Date.parse($weekof).plusDays(y).toLocaleDateString())

amardeep2021
New Contributor III

Thanks Bojan for your reply. Here is what I am trying. Filtering as per below condition and trying to add 7 days to weekof field value.

($weekof<$post_prod_support7 && $weekof != null && $weekof != ‘’)

But, I am getting below error when try adding 7 days to weekof. I tried with and without Date.parse($weekof). I am still getting error. Kindly help.

PFA of screen.

Regards,
Amar.

Screen Shot 2022-01-24 at 10.21.58 AM
Screen Shot 2022-01-24 at 10.24.06 AM
Screen Shot 2022-01-24 at 10.25.51 AM

bojanvelevski
Valued Contributor

Check my original reply, parse the stringified version of the field… Date.parse($weekof.toString).plusDays(7)