Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Click Here
Getting VB.NET Help is Easy!

Join 117,573 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 2,042 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Last Day of Month

Calculate the date of the last specified week day of the month.I.e. The last Friday.

Submitted By: AdamSpeight2008
Actions:
Rating:
Views: 689

Language: VB.NET

Last Modified: June 30, 2008
Instructions: Example

Console.WriteLine(LastDayOFMonth(New Date(2008, 7, 1), DayOfWeek.Monday).ToString)
' Return 2008/7/28

Snippet


  1. Private Function LastDayOFMonth(ByVal InputDate As Date,ByVal DayInWeek As DayOfWeek) As Date
  2.  Dim lastDay As New Date(InputDate.Year, InputDate.Month, 1)
  3.  While lastDay.DayOfWeek <> DayInWeek
  4.   lastDay  = lastDay.AddDays(1)
  5.  End While
  6.  While lastDay.Month = InputDate.Month
  7.   lastDay = lastDay.AddDays(7)
  8.  End While
  9.  lastDay = lastDay.AddDays(-7)
  10.  Return lastDay
  11. End Function

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month