Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

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.
0
JRockFL
Asked:
JRockFL
1 Solution
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now