Previous week date

Hello guys

I want to get the previous from and to date

Means if today is monday 11/03/2024

I want to get 03-03 to 10-03

that is i want to get last sunday to sunday

Hi @Gokul_Murali

Check the below expressions,

- Assign -> currentDate As DateTime = DateTime.Now
- Assign -> dayOfWeek As Integer = Convert.ToInt32(currentDate.DayOfWeek)
- Assign -> previousSunday As DateTime = currentDate.AddDays(-dayOfWeek)
- Assign -> previousSaturday As DateTime = previousSunday.AddDays(6)

- Assign -> previousWeekFrom As String = previousSunday.ToString("MM-dd")
- Assign -> previousWeekTo As String = previousSaturday.ToString("MM-dd")

Hope it helps!!

Hope it helps!!

Hi @Gokul_Murali

previousSunday = DateTime.Today.AddDays(-(7 + CInt(DateTime.Today.DayOfWeek - DayOfWeek.Sunday)))
sundayBeforePrevious = previousSunday.AddDays(-7)

Hope it helps!!

Hey @Gokul_Murali
you can try use invoke code:

Dim todayDate As DateTime = New DateTime(2024, 3, 11) 'Set this to DateTime.Now
Dim previousSunday As DateTime
previousSunday = todayDate.AddDays(-1 * ((CInt(todayDate.DayOfWeek) + 7) Mod 7))
fromDate = previousSunday.AddDays(-7)
toDate = previousSunday

fromDate - out argument (DateTime)
toDate - out argument (DateTime)

image

you can also use two assign activity:

I made a small chage here instead of .AddDays(6) i changed to.AddDays(-7) to get 03-March

Thanks @mkankatala

1 Like

Okay @Gokul_Murali

It will work for today, may be it will not work for tomorrow, could you share your workflow what you have done.

Happy Automation!!

image

Okay @Gokul_Murali

No wrong in expression, it works.

1 Like

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