09-09-2021 01:15 PM
I need to temporarily modify a date parameter in a REST Get snap. The parameter ‘date_added’ uses the previous date:
date_added = Date.parse(Date.now().minusDays(1))
I need to change it to include the range August 1st to previous date. So, I’m thinking of something like this: 2021-08-01 - Date.parse(Date.now().minusDays(1)).
Can someone offer some examples on how I would code this? I’m not very familiar with the language in SnapLogic.
Thanks!
09-09-2021 02:02 PM
Hi @vcocco,
If you think of getting the days between those dates, then you need to just switch the places of the dates.
Math.floor((Date.now().minusDays(1)) - Date.parse("2021-08-01") / (1000*60*60*24))
But if you want to get range of dates then, use this expression.
sl.range(0, Math.floor((Date.now().minusDays(1)) - Date.parse("2021-08-01") / (1000*60*60*24))).map(x => Date.parse("2021-08-01").plusDays(x))
This will return you array with range of dates, so after the mapper you can use JSON Splitter snap to split the dates in more documents.
Regards,
Viktor Nedanovski
09-10-2021 02:25 AM
I am attaching simple pipeline, containing another solution(which will generate dates from given starting point to a previous day(calculated from today’s date)) using Sequence Snap:
Pipe_2021_09_10.slp (3.8 KB)
Regards,
Spiro Taleski