How to get Current week Monday & Friday date

bot will run on any day of week(excluding weekends) I need to fetch current on going weeks Monday and Friday date no matter if month end or 31 day month or 30day

#help #question #query #studio

@Tate_S

Please try this

Mon = DateTime.Today.AddDays(-1 * Today.DayOfWeek).AddDays(1)
Fri = DateTime.Today.AddDays(7 - Today.dayOfWeek).AddSeconds(-1).AddDays(-1)

cheers

Hi @Tate_S,

What about this

DateTime.Now.AddDays(-1*(7 + (DateTime.Now.DayOfWeek - DayOfWeek .Monday)) mod 7).Date.ToString()

DateTime.Now.AddDays(-1*(7 + (DateTime.Now.DayOfWeek - DayOfWeek .Friday)) mod 7).Date.ToString()

if you want to as list use like below

image

(DateTime.Now.AddDays(-1*(7 + (DateTime.Now.DayOfWeek - DayOfWeek .Monday)) mod 7).Date.ToShortDateString+","+DateTime.Now.AddDays(-1*(7 + (DateTime.Now.DayOfWeek - DayOfWeek .Friday)) mod 7).Date.ToShortDateString).Split(","c)

Hello,
Thanks for your response.

I noticed For Friday it’s giving 27th Jan (which is previous Friday) but it should be 3rd Feb (current week) ?

Hi @Tate_S,

Plz check this

Enumerable.Range(0,7).Select(Function (x) Today.AddDays(x - today.DayOfWeek + 1)).toList(0)

Enumerable.Range(0,7).Select(Function (x) Today.AddDays(x - today.DayOfWeek + 1)).toList(4)

Thanks,

@Tate_S

please try this

Could you please help to fetch previous week Monday & Friday date
eg: if i am running bot in 3rd week of month
Than print date of 2nd week Monday and Friday

Thanks in advance!

@Tate_S

Please try this

Mon = DateTime.Today.AddDays(-1 * Today.DayOfWeek).AddDays(-6)
Fri = DateTime.Today.AddDays(7 - Today.dayOfWeek).AddSeconds(-1).AddDays(-8)

cheers

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