Click here to Skip to main content
Click here to Skip to main content

Tagged as

Date & Day Name of Current Month in SQL Server Stored Procedure

, 26 Nov 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
SQL Server Stored Procedure
This is a SQL Stored Procedure which will return a table having dates and day names of the current month. This will be helpful for any calender control related coding.
 
Create Procedure [dbo].[Current_Month_Days]
 
As
Begin
 
Declare @myDate Datetime
Set @myDate = getdate()
 
Declare @LastDay int
 
Set @LastDay = (SELECT DATENAME(d,(DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)))))
 
-- Select @LastDay

Create Table #temptable( DateField Datetime, DayField Varchar(10))
 
DECLARE @intFlag INT
SET @intFlag = 1
WHILE (@intFlag <= @LastDay)
BEGIN
 
insert into #temptable(DateField,DayField) values((DATEADD(dd,-(DAY(@mydate)-@intFlag),@mydate)),(DATENAME(dw , (DATEADD(dd,-(DAY(@mydate)-@intFlag),@mydate))) ))
 
SET @intFlag = @intFlag + 1
 
END
 
Select * From #temptable
 
End

License

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

Share

About the Author

Biswa Bhusan Dash
Software Developer (Senior) Cognition Group
India India
5yrs Exp in ASP.NET, C#, SQL SERVER,

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 26 Nov 2011
Article Copyright 2011 by Biswa Bhusan Dash
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid