Use SQL to build a dataset of days for the designated month . I would put that sql code into a stored procedure so that it can be used over and over without having to be tweaked for the current month/year. Here's the SQL you need to do that. Just give it a date in the month/year in which you are interested, and it will return the info you want for the entire month. Once you get this data, you can simply loop through the returned data set and populate your calendar.
declare @startDate DATE = DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0);
declare @endDate DATE = DATEADD(DAY,-1,DATEADD(month, DATEDIFF(month, 0, @startDate)+1, 0))
select @startDate, @endDate
SET NOCOUNT ON;
if (@endDate = '1900-1-1')
BEGIN
SET @endDate = CAST(GETDATE() AS DATE);
END
if (@startDate = '1900-1-1')
BEGIN
SET @startDate = DATEADD(YEAR, -5, @endDate);
END
IF (@startDate > @endDate)
BEGIN
DECLARE @temp date = @startDate;
SET @startDate = @endDate;
SET @endDate = @temp;
END
;WITH n AS
(
SELECT TOP (DATEDIFF(DAY, @startDate, @endDate) + 1) n = ROW_NUMBER() OVER (ORDER BY [object_id])
FROM sys.all_objects
)
SELECT DATEADD(DAY, n-1, @startDate) AS CalendarDate
,DATEPART(YEAR, DATEADD(DAY, n-1, @startDate)) AS CalendarYear
,DATEPART(MONTH, DATEADD(DAY, n-1, @startDate)) AS CalendarMonth
,DATEPART(WEEKDAY, DATEADD(DAY, n-1, @startDate)) AS WeekDayNumber
,DATENAME(WEEKDAY, DATEADD(DAY, n-1, @startDate)) AS WeekDayName
,DATENAME(MONTH, DATEADD(DAY, n-1, @startDate)) AS [MonthName]
,DATEPART(DAY, DATEADD(DAY, n-1, @startDate)) AS [DayOfMonth]
FROM n
This is a modified version of an CP article I wrote last year. I simply removed all the crap you didn't need for this task.
Build a Calendar Without Pre-Existing Tables[
^]