cancel
Showing results for 
Search instead for 
Did you mean: 

How to divide dates in to custom quarters

vaidyarm
Contributor

I have a special quarter division requirement where I have to allot data to different quarters based on the dates they belong, for this I need to get the first Monday of each month, tried the below logic to get it but not working for the Monday part.

Date.parse(‘2022-02-03’).getDay() == 1 ? Date.parse(‘2022-02-03’) : Date.parse(‘2022-02-03’).withDayOfWeek(1)

3 REPLIES 3

j_angelevski
Contributor III

Do you have a predefined set of dates, or you want to generate all quarters within SnapLogic and then get the first Monday of each month ?

Sorry, I guess I read it a bit incorrect, it’s more complicated than I thought it would be,

Details:

  • Last quarter always end on November’s last Friday (i.e. 4th quarter whatever be the date on that Friday)
  • Hence next year’s 1st quarter will start from Saturday (whether it be from the month of November or December).
  • each quarter is of 91 days, this more clear from the below image

image

bojanvelevski
Valued Contributor

Hey @vaidyarm,

There’s a very interesting function sl.range() that will come in handy in cases when working with dates. The pipeline below will produce the quartals for this year while meeting the conditions you stated in your previous posts.

Check this and tell me what you think
This year quartals_2022_03_23.slp (8.4 KB)