471,853 Members | 1,712 Online

# Last Friday of each month

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
May 23 '07 #1
3 5807
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,

' 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

End Function
news:3l****************************@40tude.net...
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
May 23 '07 #2
On Wed, 23 May 2007 23:47:29 +1200, Stephany Young wrote:
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,

' 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

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
May 23 '07 #3
ats@jbex wrote:
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
May 23 '07 #4

### This discussion thread is closed

Replies have been disabled for this discussion.