How to find the date of First thrusday of months(Feb,May,Aug &Nov).
Thx in advance
How to find the date of First thrusday of months(Feb,May,Aug &Nov).
Thx in advance
HI,
The following expression helps you.
Enumerable.Range(1,7).Select(Function(i) New DateTime(2022,2,i)).Where(Function(d) d.DayOfWeek = DayOfWeek.Thursday).Single()
OR
Enumerable.Range(1,7).Select(Function(i) New DateTime(2022,2,i)).Where(Function(d) d.DayOfWeek = DayOfWeek.Thursday).Single().ToString()
Please modify 2022 and 2 to required year and month.
Regards,
@Yoichi Thx a lot it works.
If possible can you please explain this script.
Hi,
Enumerable.Range(1,7)
returns numbers from 1 to 7.
Then, Select(Function(i) New DateTime(2022,2,i))
returns dates from 2022 Feb 1 to 2022 Feb 7 because i
is applied from 1 to 7.
Next, Where(Function(d) d.DayOfWeek = DayOfWeek.Thursday)
filters the above dates whether Thursday. Remaining is what you need. (As return type of Where method is IEnumerable<DatatIme>
, we need to extract one result using Single method.)
Hope this helps you.
Regards,
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.