Sort Date by Month

Hi Guys,

I have a column date in my DataTable and i want to sort the date by Month.

How can i do that?

Thanks and Happy Automations,

1 Like

HI @jmeier

Try this below expression

(From r In DT Order By DateTime.ParseExact(r.Item(“YourColumnName”).ToString, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture) Descending Select r).CopyToDataTable

MM/dd/yyyy → Date format of the column date


dt.AsEnumerable.OrderBy(Function(r) Convert.ToDateTime(r(“Date_column”))).CopyToDataTable

Hi Gokul001,

I want to sort only by month.

For example i have this dates (19/02/1993;18/02/1991;17/01/2001). I want this to be sorted like:

I @Gangadhar_Athili ,

Didn t work. I want to sort by Month, regardless of the year.


1 Like


Hope the below steps would help you resolve this

As you want to sort only on month basis this needs some tweak before sorting them out

  1. Hope you have a datatable named dt

  2. Use a add datacolumn activity and mention column name temp_col and mention datatable as dt so that it gets added at last to the datatable and mention type argument as int32

  3. Now use a FOR EACH ROW activity and mention dt as input

  4. Inside the loop use a assign activity like this

row(“temp_col”) = Convert.ToInt32(Split(row(“Date_columnname”).ToString, “/“)(1).ToString.Trim)

  1. Now outside this loop use a SORT DATATABLE activity and pass dt as input and mention the column name as temp_col and mention ascending or descending

  2. Now you will get the datatable sortrd based on this temp col and you can see the date column arranged in the order you want

  3. Let’s delete the temp column now with remove datacolumn activity so that you get the chat output you want

Cheers @jmeier

1 Like

Did that work in your scenario @jmeier

Hi @Palaniyappan

Yes, is a good work around.


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