Click here to Skip to main content
11,712,143 members (65,159 online)
Click here to Skip to main content

Tagged as

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

, 26 Nov 2011 CPOL 14.2K 2
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]
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))
SET @intFlag = 1
WHILE (@intFlag <= @LastDay)
insert into #temptable(DateField,DayField) values((DATEADD(dd,-(DAY(@mydate)-@intFlag),@mydate)),(DATENAME(dw , (DATEADD(dd,-(DAY(@mydate)-@intFlag),@mydate))) ))
SET @intFlag = @intFlag + 1
Select * From #temptable


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


About the Author

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

You may also be interested in...

Comments and Discussions

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