473,657 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Last Friday of each month

ats
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 6114
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 LastFridayOfMon th(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.Day OfWeek, 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***@allenjon es.NOSPAM.co.PL EASE.ukwrote in message
news:3l******** *************** *****@40tude.ne t...
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
ats
On Wed, 23 May 2007 23:47:29 +1200, Stephany Young wrote:
Public Shared Function LastFridayOfMon th(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.Day OfWeek, 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
3595
by: SimonC | last post by:
I would like to return data from the last 2 weeks of each given month in Javascript, but in 2 formats. So, the penultimate week (Monday to Sunday) and the last week (Monday to ??) I'm not sure if it can be done, but all help welcomed. E.g. I have December and would like to see the last 2 weeks.. So this doesnt mean the last 15 days. What i mean by this is...
3
6609
by: Melissa | last post by:
I have this table: TblProjectYear ProjectYearID ProjectYearStartDate ProjectYearEndDate The Project Year will always span across December 31; for example 9/1/04 to 6/30/05. How do I build a combobox based on this table that will display all the months between the StartDate and the EndDate for a given ProjectYearID and when a selection is made, the full date of the last day of the selected
2
12030
by: Sasidhar Parvatham | last post by:
Hello All, Is there a way I can get dates for first and last fridays of a month? Any suggestion would be helpful. Thanks.
2
2935
by: rf | last post by:
Hey I need to be able to get the dates from last wednesday to the past tuesday on thursday or friday every week. How would I do that? For example: m t W TH F M T w th f I would need the dates of the CAPITAL W and T when I run the script from the last th or f
10
32785
by: sherifffruitfly | last post by:
Hi all, This is how I'm currently getting Friday of last week. It strikes me as cumbersome. Is there a slicker/more elegant way? Thanks for any ideas, cdj
1
2177
by: Svetac | last post by:
Hi, I use a script that shows when the page was last modified. It works fine for just one html file. The thing I would like to do is that the script shows me of last modified file in root directory. For example if I change something in gallery.html or feed.xml, I would like to see that date of change in index.html under last modified date. Could someone help me please. Thanks in advance. The script that I use now:
0
2359
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and ASP.NET a DataGrid with Updatable rows based on a date retrieved from a data table in SQL Server. Below is the design algorithm. 1. Retrieve the Max(rundate) From MyDataTable 2. If the current month -1 = rundate .month from step 1 then 2a. ...
8
3960
code green
by: code green | last post by:
I need to generate the date for the latest Friday and the Saturday previous to this ie 7 days. I am generating reports for the periods Yesterday, Month to date and Sat-Fri so I create the dates in PHP and pass them to a function to be used in the BETWEEN phrase of a query. This could run almost any day of the week but most probably the Friday itself. I have figured it out for yesterday $start = date('Y-m-d',strtotime('-1 day')); $finish...
1
3058
by: karuppiah | last post by:
Hi All, i need query,how to select last 3 month ,last 3wek,last 3 days , this last 3 month and 3 week should be friday, using sysdate from dual table, there is no exsting table, pls any one help me. Regards, karuppiah.
0
8303
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8502
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.