cancel
Showing results for 
Search instead for 
Did you mean: 

Need to open up a date parameter

vcocco
New Contributor II

I need to temporarily modify a date parameter in a REST Get snap. The parameter ‘date_added’ uses the previous date:
SnapLogicForumDateParameter

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!

2 REPLIES 2

viktor_n
Contributor II

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

SpiroTaleski
Valued Contributor

@vcocco

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