Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

GET CERTAIN DATES

Hi All,

I want to set default dates with condition :

1. If Current Date is Tuesday To Sunday
    FromDate = Last Sunday Date
    ToDate = Current Date

2. If Current Date = Monday
    FromDate =  Sunday before Yesterday of Current Date
    ToDate = Saturday

How could I do it ?

Thank you.
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

  Dim offset as Integer
   Select Case Today.DayOfWeek
      Case DayOfWeek.Monday : offset = -8
      Case DayOfWeek.Tuesday : offset = -2
      Case DayOfWeek.Wednesday : offset = -3
      Case DayOfWeek.Thursday : offset = -4
      Case DayOfWeek.Friday : offset = -5
      Case DayOfWeek.Saturday : offset = -6
      Case DayOfWeek.Sunday : offset = -7
   End Select
   Dim fromDate as Date = DateAdd(DateInterval.Day, offset, Today)
   Dim toDate as Date = Today
   If Today.DayOfWeek = DayOfWeek.Monday Then
      fromDate = DateAdd(DateInterval.Day, -2, Today)
   End If
Avatar of emi_sastra
emi_sastra

ASKER

Hi cyberkiwi,

Why toDate always Today?

If today is monday then show sunday to saturday of last week
If today is > monday then show recent sunday to today.

Thank you.

ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes,  it works.

Thank you very much for your help.