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
"ats@jbex" <al***@allenjones.NOSPAM.co.PLEASE.ukwrote in message
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