Last Friday of each month

A

ats@jbex

Does anybody have any sample code for calculating the date for teh last
Friday in each month.

TIA
--
ats@jbex

When an old lady got hit by a truck
I saw the wicked gleam in your eyes

Adam and The Ants - Whip In My Valise
 
S

Stephany Young

This function returns the date of the last friday of the specified
month/year combination.

In countries that were under the influence of Great Britain in 1752 or were
established after 1752 by the British then the function holds good for any
month/year combination from January 1753 onwards.

For other countries one needs to determine when the calendar was last
adjusted for the lack of leap-years and NOT use the function for month/year
combinations before that point in time.

Public Shared Function LastFridayOfMonth(ByVal month As Integer, ByVal
year As Integer) As DateTime

' Calculate the date for the last day of the specified month/year
combination.
Dim _date As DateTime = (New DateTime(year, month,
1)).AddMonths(1).AddDays(-1)

' Grab the DayOfWeek for that date (0 = Sunday ... 6 = Saturday)
Dim _dayofweek As Integer = CType(_date.DayOfWeek, Integer)

' Calculate the offset to the preceeding Friday
Dim _offset As Integer = _dayofweek - (_dayofweek + 1) * 2
If _offset < -6 Then _offset += 7

' Return the adjusted date
Return _date.AddDays(_offset)

End Function
 
A

ats@jbex

Public Shared Function LastFridayOfMonth(ByVal month As Integer, ByVal
year As Integer) As DateTime

' Calculate the date for the last day of the specified month/year
combination.
Dim _date As DateTime = (New DateTime(year, month,
1)).AddMonths(1).AddDays(-1)

' Grab the DayOfWeek for that date (0 = Sunday ... 6 = Saturday)
Dim _dayofweek As Integer = CType(_date.DayOfWeek, Integer)

' Calculate the offset to the preceeding Friday
Dim _offset As Integer = _dayofweek - (_dayofweek + 1) * 2
If _offset < -6 Then _offset += 7

' Return the adjusted date
Return _date.AddDays(_offset)

End Function

Thanks for the code. I will try that also. No worries re the earlier dates.
It's for a web page so our employees will know what date is payday for any
given month.

Thanks
--
ats@jbex

The cracks between the paving stones
Look like rivers of flowing veins.
Strange people who know me
Peeping from behind every window pane

The Who - The Real Me
 
A

Andrew Morton

ats@jbex said:
Thanks for the code. I will try that also. No worries re the earlier
dates. It's for a web page so our employees will know what date is
payday for any given month.

If the last Friday in a month falls on a [national | bank | whatever]
holiday, is that still payday, or is the payday moved forward?

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Email Archive program 12
int.TryParse 9
Server.MapPath 3
VB.Net Datagrid 5
Excel Date of first friday every month 3
RichTextBox 4
Last Friday of the month 9
Last working day of a month 12

Top