Link to home
Start Free TrialLog in
Avatar of lbsi
lbsiFlag for United States of America

asked on

Finding a Date based on parameter

Good Afternoon

My current project involves finding dates relative to a "certain" date itself.  Can you all suggest if there is a method to help me produce the desired
result.  Here is what I am looking for:

FirstOfMonth - Date of the first day of current month
LastOfMonth - Date of the last day of current month
FirstOfLastMonth - Date of the first day of previous month
LastOfLastMonth - Date of the last day of previous month
FirstOfYear - Date of first day of the year
LastOfYear - Date of last day of the year
CurrentWeekMonday - Date of Monday of the current week(If it is Sunday then tommorrow, else today or last Monday.)
CurrentWeekFriday - Date of Friday of the current week(Future Friday unless today is Fri or Sat)
LastWeekMonday - Date of Monday of previous week(If it is Sunday then 6 days ago, else the last week's Monday at least 7 days ago)
LatWeekFriday - Date of Friday of previous week(Previous Friday 2 to 8 days ago)

Thanks for the help,
Ed
Avatar of AlexFM
AlexFM

   Function FirstOfMonth() As DateTime
        Return New DateTime(Now().Year, Now.Month, 1)
    End Function

    Function LastOfMonth() As DateTime
        Return New DateTime(Now().AddMonths(1).Year, Now().AddMonths(1).Month, 1).AddDays(-1)
    End Function

    Function FirstOfLastMonth() As DateTime
        Return New DateTime(Now().AddMonths(-1).Year, Now().AddMonths(-1).Month, 1)
    End Function

    Function LastOfLastMonth() As DateTime
        Return FirstOfLastMonth().AddDays(-1)
    End Function

I hope you can continue this.
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

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
Avatar of lbsi

ASKER

Thanks for the help...I knew there had to be an easier way than what I was trying.

Have a good day,
Ed