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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating payperiods for future dates

Status
Not open for further replies.

ninelgorb

Programmer
Mar 7, 2005
111
US
The pay period at my company is from sunday to saturday.
How can I calculate these pay periods for the next 5 years.

Example:

StartPeriod EndPeriod
20050612 20050618
20050619 20050625
20050626 20050702

Thanks,
Ninel
 
something like this should work
Code:
declare @begindate datetime, @enddate datetime

select @begindate = '5/1/2005',
    @enddate =	'5/1/2010'



create table #workweek( begindate datetime,enddate datetime)

-- only need if it is not set to 7
SET DATEFIRST 7


-- create that nasty table
insert into #workweek select @begindate-(DATEPART(dw,@begindate)-1), (@begindate-(DATEPART(dw,@begindate)-1))+ 6 

while (select max(enddate) from #workweek) < @enddate
begin
insert into #workweek select max(begindate)+7,max(begindate)+13 from #workweek
end



select * from #workweek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top