As you said, it is little bit complex but not impossible. With small thought you might get this easily. I’ve implemented code but to give your brain some work I’m not posting the code but giving you pseudo code below.
I thought of following way. First you need to have a duration through which you want to divide a year, for ex: 6 months.
Take the start date and create a new date by using DateTime constructor (year, month, day) and pass the year in the start date as year and month and day as 1 as below:
new DateTime(startdate.Year, 1, 1);
This will give you start date of that year. Then add duration days/months to that date to get the next periodicity. If your start date is less than this new date then add once again duration to that new date till you get the date greater than start date.
With the above logic you can form the periods you want till the end date. Of course you have to check whether your end date as well against this periodicity. There are many other conditions you need to check to get the proper system to give these periods for any given start and end dates.
1
solved function which divides time period by periodicity