Date Automation

I want to get every week End date i.e ( sunday) of a month .
if there are 4 weeks in a month then 4 sunday dates should be shown.
if 5 weeks are there in month then 5 weeks end date should be shown.
All date week end should be shown in excel.

Hello @Ak_4

You can use the Modify Date Activity.


Hi @Ak_4,

Hope following helps your request

td(System.DateTime) = DateAndTime.Today

list_Sunday (System.Collections.Generic.List<System.DateTime>) = Enumerable.Range(1,DateTime.DaysInMonth(td_TodayDate.Year,td_TodayDate.Month)).Select(function(d) new DateTime(td_TodayDate.Year,td_TodayDate.Month,d)).Where(function(x) x.DayOfWeek=DayOfWeek.Sunday).ToList()

Note: list_Sunday is List<System.DateTime>


Getting an error

Hi @Ak_4 ,

Alternately we could perform the below Implementation :

  1. Get the First day of Month using Assign Activity in the below way :
firstDayOfMonth = new DateTime(now.Year,Now.Month,1)

Here, firstDayOfMonth is a DateTime type variable

  1. Get the First Sunday of the month from the First Day of Month :
firstSundayOfMonth = if(firstDayOfMonth.DayOfWeek.ToString.Equals("Sunday"),firstDayOfMonth,firstDayOfMonth.AddDays(7-firstDayOfMonth.DayOfWeek))

Here, firstSundayOfMonth is a DateTime type variable.

  1. Get all Sundays in the month by adding multiples of 7 to the First Sunday date.
sundaysInMonth = Enumerable.Repeat(7,7).Where(Function(x,i)firstSundayOfMonth.AddDays(x*i).Month=Now.Month).Select(Function(x,i)firstSundayOfMonth.AddDays(x*i)).ToArray

Here, sundaysInMonth is an Array of DateTime type variable.

Let us know if you were able to follow this approach.

1 Like