Help with Sum in DT based on Long date

Hello,

I want to make the sum of every item that is sold on a certain date, not certain hour or minute. I read this in a range workbook. But then I’m stuck.

[Datum,Naam,Hoeveelheid
01/31/2025 21:51:00,Dagschotel 1,1
01/31/2025 21:52:00,Dagschotel 9,1
01/31/2025 21:52:00,Dagschotel 12,1
02/01/2025 04:48:00,Dagschotel 11,1
02/01/2025 04:49:00,Dagschotel 11,1
02/01/2025 21:24:00,Dagschotel 7,1
02/01/2025 21:25:00,Dagschotel 11,1
02/01/2025 21:25:00,Dagschotel 7,1
02/02/2025 20:18:00,Dagschotel 7,1
02/02/2025 20:35:00,Dagschotel 13,1
]

As I don’t really have a programming background. I took a code from a topic in the forum, adjusted it a bit, I already got it working for one part of my project. But I can’t seem to make it work because I got time stamps hh:mm. Resulting in only making the items bought the same time, instead of the same day.

dt_AutomaatDagschotel.AsEnumerable().GroupBy(Function(r) r(“Datum”).ToString()).Select(Function(g) dt_AutomaatDagschotel.Clone().LoadDataRow({g.Key, g.First()(1), g.Sum(Function(r) CInt(r(“Hoeveelheid”)))}, False)).CopyToDataTable()

Question 1: How can I easily change a DateTime in a row in a DT so I can only have the date? Or Adjust it to MM/dd/yyyy 00:00:00?

Question 2: Can you adjust the code to make it work, or make some other code that works.

Hi @sallegae

Use the below vb code in Invoke code activity to change the date style to MM/dd/yyyy

For Each row As Datarow In dt.asenumerable
row("Datum") = DateTime.ParseExact(row("Datum").ToString, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")
Next

Hope it helps!!

@sallegae,

Check if this what you are looking for

Output:

Sample code:

SampleDemoCode.zip (143.2 KB)

Thanks both.

Both solutions work.

1 Like

It’s my pleasure to help you… @sallegae

Happy Automation!!

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