Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3rd to last Business Day of Every Month

Status
Not open for further replies.

cfash

Programmer
Nov 22, 2000
8
US
I have no idea where to even start attacking this problem.

Can anyone give me a suggestion as to how I might be able to figure out the third to last BUSINESS DAY of every month? This is a significant date for my application and I need a way to figure it out.

Any suggestions are appreciated.

Chris
 
Well, I am not sure if I understood your question.
1) Do you need to find out two days i.e. the 3rd and the last business day in any given month?
2)Or do you need to know all the business days between the 3rd and last business day in any given month
 
You can use the VBScript function Weekday(date) to return a number corresponding to what week day it is (1 = Sunday, and so on). You could test the last day of your month on this to figure out what day of the week it is, then move back a few days if you need to, to find the third-to-last business day of the month. You can use DateAdd to move back a few days from the end of the month.

(Assuming: if Friday is the last business day of the month, then Tuesday is the third-to-last business day).

theday = Weekday(date)
newnay = DateAdd(interval, number, date)
where interval is "d" for day and number is how many intervals you want to move (negative in this case) and date is your original date. Harold Blackorby
hblackorby@scoreinteractive.com
St. Louis, MO
 
here it is in JScript... hope it helps..

function lastBusiness()
{
var x = new Date();
var month = x.getMonth();
var year = x.getFullYear();
var febdays = (!(year%4) && !(!(year%100) && (year%400)))?29:28;
var days = new Array(31, febdays, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var z = new Date((month+1)+"/"+days[month]+"/"+year);
var lastDay = z.getDay();
alert(lastDay)
alert(z)
var lastDate = 0;
switch(lastDay)
{
case 6:
lastDate = days[month] - 3;
break;
case 5:
lastDate = days[month] - 2;
break;
case 4:
lastDate = days[month] - 2;
break;
case 3:
lastDate = days[month] - 2;
break;
case 2:
lastDate = days[month] - 4;
break;
case 1:
lastDate = days[month] - 4;
break;
case 0:
lastDate = days[month] - 4;
break;
}
month++;
return month+"/"+lastDate+"/"+year;
}

alert(lastBusiness()) adam@aauser.com
 
oops meant to take the alerts out.

function lastBusiness()
{
var x = new Date();
var month = x.getMonth();
var year = x.getFullYear();
var febdays = (!(year%4) && !(!(year%100) && (year%400)))?29:28;
var days = new Array(31, febdays, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var z = new Date((month+1)+"/"+days[month]+"/"+year);
var lastDay = z.getDay();
var lastDate = 0;
switch(lastDay)
{
case 6:
lastDate = days[month] - 3;
break;
case 5:
lastDate = days[month] - 2;
break;
case 4:
lastDate = days[month] - 2;
break;
case 3:
lastDate = days[month] - 2;
break;
case 2:
lastDate = days[month] - 4;
break;
case 1:
lastDate = days[month] - 4;
break;
case 0:
lastDate = days[month] - 4;
break;
}
month++;
return month+"/"+lastDate+"/"+year;
}

alert(lastBusiness()) adam@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top