Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i find out next three dates greater than a given dates but condition is that the day occourance is same for all these three days , actually i am selecting day name from my table
and i want to get these three dates by calculation (these dates are not in my table )

alter procedure Select_Disurbment_Dates

as
begin
(
@Dayname varchar(300)

)
declare @max_Id int,@previousDate datetime,@current_system_date datetime,@FirstDate datetime, @Min_disburment_date datetime
set @max_Id=(select MAX(dayopencloseid) from DayOpenDayCloseInfo
where CollectionByLoanOfficerStatus=1 and DayCloseByAdminStatus=1 )

set @previousDate=(select CenterCollectionDate from DayOpenDayCloseInfo where dayopencloseid=@max_Id)

set @current_system_date=(Select DATEADD(d,1, @previousDate) as Current_SystemDate )
--set @FirstDate=(Select DATEADD(d,7, @current_system_date) )
set @Min_disburment_date=(Select DATEADD(d,14, @current_system_date) )




end


for example .. ..

date that i got through procedure(i.e. @Min_disburment_date) is 15/08/2013
and my procedure parameter (i.e. @Dayname ) value is 'Saturday' . so i want to select next three dates of 15/08/2013 which has day 'Saturday' and the resulted dates are ...

17/08/2013
24/08/2013
31/08/2013

both these dates have saturday


pls suggest .. i am tired to do this ... :)
Posted

1 solution

Try this...

SQL
declare @Dayname varchar(25)
declare @Min_disburment_date datetime
set @Dayname = 'Saturday'
set @Min_disburment_date = '15-Aug-2013'

select @Dayname, @Min_disburment_date, DateName(weekday,@Min_disburment_date)

WHILE DateName(weekday,@Min_disburment_date) <> @Dayname
	BEGIN
		SET @Min_disburment_date = dateAdd(d,1,@Min_disburment_date)
	END

select @Dayname, @Min_disburment_date, dateAdd(d,7,@Min_disburment_date), dateAdd(d,14,@Min_disburment_date)
 
Share this answer
 
Comments
GDdixit 22-Aug-13 2:26am    
thnx dude ... ur solution working perfactly :)
Dineshshp 22-Aug-13 3:26am    
Hello dude.. Don't Forget To Vote Yaar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900