Solved

Finding a Date based on parameter

Posted on 2006-11-06
3
255 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
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio Front End "Web Forms" For SQL Server Tables 5 73
Definitions and default visual studio colors 5 58
SQL syntax in VB.net 5 29
Vb. Net application freezes 9 30
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

22 Experts available now in Live!

Get 1:1 Help Now