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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
emi_sastraAuthor Commented:
Yes,  it works.

Thank you very much for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.