Hello there.
This might be an easy one but i coudnt make it work yet:
Need to filter a datatable column (as type date) at the condition:
If the day is monday then
Filter monday, sunday, saturday and friday dates.
Lets say monday is 28/09
Then the filtered output datatable must have
28/09, 27/09, 26/09, 25/09.
Tried using the default datatable but it doesnt work good.
LINQ solution would help but I wanted the cleanest way if possible.
Public Class Main
Public Shared Sub Main()
’ Input date
Dim inputDate As DateTime = DateTime.Now ’ You can replace this with your variable date
' Check if the input date is Monday
Dim isMonday As Boolean = inputDate.DayOfWeek = DayOfWeek.Monday
If isMonday Then
' Calculate the dates for the previous Friday, Saturday, and Sunday (T-3)
Dim previousFriday As DateTime = inputDate.AddDays(-3)
Dim previousSaturday As DateTime = inputDate.AddDays(-2)
Dim previousSunday As DateTime = inputDate.AddDays(-1)
Else
End If
End Sub
Hi Please find the update code for your new query. In the Else part i have added additional condition’s.
Check if the input date is Monday
Dim isMonday As Boolean = inputDate.DayOfWeek = DayOfWeek.Monday
If isMonday Then
' Calculate the dates for the previous Friday, Saturday, and Sunday (T-3)
Dim previousFriday As DateTime = inputDate.AddDays(-3)
Dim previousSaturday As DateTime = inputDate.AddDays(-2)
Dim previousSunday As DateTime = inputDate.AddDays(-1)
Else
Dim Currendate as datetime = DateTime.Now
Dim previousDate As DateTime = inputDate.AddDays(-1)