?
Solved

Finding a Date based on parameter

Posted on 2006-11-06
3
Medium Priority
?
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17883841
   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 2000 total points
ID: 17883879
   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
ID: 17884185
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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