Select last business day function

How I would I calculate the last business day, not including today?
For example, The last business day would be Friday 5/26/2006
I have a table called holidays and it has 5/29/2006 in it.
LVL 8
JRockFLAsked:
Who is Participating?
 
bwdowhanCommented:
Hi JRockFL,

The easiest way to handle this is to have an entire calendar table (not just holidays).. A good link with most of the code to create, populate, and query a table like this can be found here:

http://www.aspfaq.com/show.asp?id=2519

With this table, you could then select the max(d) where the month = the current month, or next month, or whatever.

Brian
0
 
imran_fastCommented:
Assume your last working day is Friday and weekend starts from Saturday then use the below code
it will give you last working day for the current month

declare @LastDate as datetime
select  @LastDate  =
      dateadd(day,-1,
      cast(
      cast(datepart(year,dateadd(month,1,getdate())) as varchar(10))+'-'+
      cast(datepart(month,dateadd(month,1,getdate())) as varchar(10))+'-'+
      '01' as datetime)
      )
WHILE  datename(weekday,@LastDate) <> 'Friday'
begin
set @LastDate = dateadd(day,-1,@LastDate)
end

select @LastDate
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.