Hi all,
I need to find week range of a date
Ex if date is 25 Dec it should write
25 December to 29 december
If date is 20 december it should write
18th December to 22nd december
And also it needs to find whether date falls to previous weeks
Ex if date is 14 Nov
It should say previous week
Thanks
Parvathy
(PS Parvathy)
2
Hi @Kishore_Raj
Check out this thread. It will help you
- Assign: dateInput = "25 Dec"
- Assign: str_date = DateTime.ParseExact(dateInput, "dd MMM", System.Globalization.CultureInfo.InvariantCulture)
- Assign: str_dayOfWeek = Convert.ToInt32(str_date.DayOfWeek)
- Assign: weekStart = str_date.AddDays(-str_dayOfWeek)
- Assign: weekEnd = weekStart.AddDays(6)
- Assign: weekRange = weekStart.ToString("dd MMM yyyy") & " to " & weekEnd.ToString("dd MMM yyyy")
- Assign: currentDate = DateTime.Now
- Assign: isPreviousWeek = If(str_date < currentDate.AddDays(-7), True, False)
- If: isPreviousWeek
- Message Box: weekRange & vbCrLf & "Previous week"
- Else
- Message Box: weekRange & vbCrLf & "Current week"
Note: str_date, weekStart, weekEnd is of DataType System.DateTime. str_dayOfWeek is of DataType System.Int32
Hope it helps!!
Regards
Yoichi
(Yoichi)
3
Hi,
Can you try the following sample?
targetDate = DateTime.ParseExact(“25 Dec”,“d MMM”,System.Globalization.CultureInfo.InvariantCulture)
Then
startDate = targetDate.AddDays(-1*CInt(targetDate.DayOfWeek)+1)
endDate =targetDate.AddDays(-1*CInt(targetDate.DayOfWeek)+5)
Check if target date is after start date
Sample
Sample20231220-2 (2).zip (2.8 KB)
Regards,
ppr
(Peter Preuss)
4
Working with Activities:
get first Monday from the corresponding Week - dateWeekFirst
Similar we can also get the corresponding Friday
As an alternate, we can work with an offset array

And can get the corresponding Friday
YourMondayDateTimeVar.AddDays(4)
unclear on which the 14 nov is related as compared to all other december dates from above it is different month.
For weeks check: check the week number

and compare to week number from other date
ppr
(Peter Preuss)
5
with a different interpretation of
Maybe a simple
dateTimeVar1.Date < dateTimeVar2.Date
will work as it returns true when it date1 is before date2