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.
LVL 1
emi_sastraAsked:
Who is Participating?
 
cyberkiwiCommented:
Sorry, was shifting variables, the last part should have been:

 Dim fromDate as Date = DateAdd(DateInterval.Day, offset, Today)
   Dim toDate as Date = Today
   If Today.DayOfWeek = DayOfWeek.Monday Then
      toDate = DateAdd(DateInterval.Day, -2, Today)
   End If
0
 
cyberkiwiCommented:
  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
0
 
emi_sastraAuthor Commented:
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.

0
 
emi_sastraAuthor Commented:
Yes,  it works.

Thank you very much for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.