Create dynamically datatables based on start date and end date

Hi,

I have a task that needs to separate the contents of the data table based on the pair of dates.

Below is how my data table looks like. I need to separate each record based on their start date and end date.

For example, I have two entries for 9/21/2017 and 9/25 2017m I need to insert it to another datatable which will be created dynamically.

The next date is 9/22/207 and 9/27/2017, i need this to be also on another different data table to be added .

And the same for 9/24/2017 and 9/27/2017. I need to create the datatable on memory instead of creating a build datatable manually.

image

Hope someone can help me.

@dhennespiritu

Unfortunately the requirements are in a way that it can be interpretated in more different ways. However it was understood that each rows of distinct pair of Start Date and corresponding End Date are to bring into a datatable

Find starter help here, implementing this with a LINQ statement based on the Group By approach:
dhennespiritu.xaml (9.4 KB)

It is not predictible as the dates from excel will come / looks like in the datatable. Thats why following line is implemented to get prepared for quick adoptions:

(From d In dtData.AsEnumerable
Group d By k1=DateTime.ParseExact(d("Start Date").toString.Trim, "M/dd/yyyy",CI).Date,
                    k2=DateTime.ParseExact(d("End Date").toString.Trim, "M/dd/yyyy",CI).Date Into grp=Group
Select grp.CopyToDataTable).toList

e.g. start date
k1=DateTime.ParseExact(d(“Start Date”).toString.Trim, “M/dd/yyyy”,CI).Date

With finetuning the date format e.g. additonal time info the parsing will handle this as well. For grouping it was set on the date without the time

Let us know your feedback
with

2 Likes

this solution worked! thank you very much!

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