How to split the Date range based on input

Hi,

I need to split the date range based on input like below

Start date: 01/01/2025 End date: 01/31/2025
input number:3
need to split these dates in 3 sets
set1: {01/01/2025, 01/10/2025}
set2:{01/11/2025, 01/20/2025}
Set3:{01/21/2025, 01/31/2025}
Could you please help me on this logic

Hi @Manaswini_UI
Please find attached solution!

I hope this will work


DateSplitter.zip (48.1 KB)

Thanks

1 Like

Hi @Manaswini_UI

Date1= DateTime.ParseExact("01/01/2025", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
Date2= DateTime.ParseExact("01/31/2025", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
inputSplitNum = 3
totalDays = (Date2- Date1).Days + 1
splitSize = totalDays \ numSets
remainder = totalDays Mod inputSplitNum

Inside For each Loop Enumerable.Range(0,inputSplitNum)

rangeStart = startDate.AddDays(index * splitSize + Math.Min(index, remainder))
rangeEnd = rangeStart.AddDays(splitSize - 1 + If(index < remainder, 1, 0))

Refer the xmal file
Main.xaml (20.3 KB)

Sample output:
image

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.