473,714 Members | 2,050 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 6129
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
3613
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
6615
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
12042
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
2943
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
32811
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
2189
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
2361
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
3966
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
3062
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
8817
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8715
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
9322
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...
0
9193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9092
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
9037
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
7963
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...
1
6641
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4734
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.