To Find No.of Days in a month and enter working days into table
Here I am Creating a stored procedure for Finding No.of Days in a month.
You can pass the date from your front-end.I am setting a Date manually.Here adding the date of February 2013.Just check how many days in 2012 February.In front-end you can use a calender control and select the date and pass it.
And Suppose you have a table as Working days.How to enter the days of a month into the table.
Just Try
Here I am Creating a stored procedure for Finding No.of Days in a month.
You can pass the date from your front-end.Here I am setting a Date manually.
CREATE PROCEDURE [dbo].[Stp_GetDays]
AS
DECLARE @date datetime,@Month datetime,@Days int
BEGIN
set @date='2013-02-01'
Select @Month=DATEADD(MONTH,1,@date)
set @Days = DAY(@Month - DAY(@Month))
select @Days [No.Of Days]
END
Here adding the date of February 2013.Just check how many days in 2012 February.
In front-end you can use a calender control and select the date and pass it.
And Suppose you have a table as Working days.To enter the whole days of a month(eg:January 2013) into the table you can use this code.And after entering into the table,you can mark 0 for nonworking day for the field IsWorkingDay.
CREATE PROCEDURE [dbo].[Stp_datefill]
AS
DECLARE @Today DATETIME
Declare @WorkingDate datetime
SELECT @Today = '1/1/2013'
declare @i int
set @i=1
while @i<=31
begin
select @WorkingDate = (SELECT DATEADD(dd,-(DAY(DATEADD(mm,1,@Today))-@i),DATEADD(mm,0,@Today)))
set @i=@i+1
insert into WorkingDays_DT (days,IsWorkingDay)values(@WorkingDate,1)
end
Just Try