Solved

Finding a Date based on parameter

Posted on 2006-11-06
3
251 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:lbsi
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
   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.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
Comment Utility
   Function FirstOfYear() As DateTime
        Return New DateTime(Now.Year, 1, 1)
    End Function

    Function LastOfYear() As DateTime
        Return New DateTime(Now.AddYears(1).Year, 1, 1).AddDays(-1)
    End Function
0
 

Author Comment

by:lbsi
Comment Utility
Thanks for the help...I knew there had to be an easier way than what I was trying.

Have a good day,
Ed
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now