Issue while adding days to date field in mapper

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.

Hey @amardeep2021,

Try parsing a stringified version of the date, like this:

Date.parse($weekof.toString()).plusDays(7)

1 Like

Thanks Bojan. I am able to use the expression suggested to add 7 days to date value. But it comes up with timestamp as well which I should not have. To remove timestamp I tried slice and substr fucntions both not working because of data type. Do you know how to remove timestamp from this? PFA of screenshot.

Also I want to achieve something like below.

If A <B
A = A + 7 days

Endif

Any tip for the above 2 would be helpful.

Regards,
Amar.

If you’re comparing this field with another, than parse the other field as well, do the comparison and use the .toLocaleDateString() function after, on both fields. That will help you get the date parts only.

Regards,
Bojan

Thanks Bojan. This works to trim timestamp.

Do you know how to increment the same date in loop till it reaches a specific date field value? Please let me know if you have any tips.

Regards,
Amar.

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.

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.

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())

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.25.51 AM

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