Today is 20th Aug 2013. I want to generate 20 rows which will contain dates from 1st to 20th (whatever would be the current date) of the month by using mysql query. Count should always start from 1st date of the month and till current date... output would be like, only one column and multiple rows till current date like given below..
Current month
8/1/13 12:00 AM
8/2/13 12:00 AM
8/3/13 12:00 AM
8/4/13 12:00 AM
8/5/13 12:00 AM
8/6/13 12:00 AM
8/7/13 12:00 AM
8/8/13 12:00 AM
8/9/13 12:00 AM
8/10/13 12:00 AM
8/11/13 12:00 AM
8/12/13 12:00 AM
8/13/13 12:00 AM
8/14/13 12:00 AM
8/15/13 12:00 AM
8/16/13 12:00 AM
8/17/13 12:00 AM
8/18/13 12:00 AM
8/19/13 12:00 AM
8/20/13 12:00 AM
I tried following query but is of no use. Can you please help to find some other workaround for this?
DECLARE @startDate DATETIME=CAST(MONTH(GETDATE()) AS VARCHAR) + '/' + '01/' + + CAST(YEAR(GETDATE()) AS VARCHAR) -- mm/dd/yyyy
DECLARE @endDate DATETIME= GETDATE() -- mm/dd/yyyy
;WITH Calender AS
(
SELECT @startDate AS CalanderDate
UNION ALL
SELECT CalanderDate + 1 FROM Calender
WHERE CalanderDate + 1 <= @endDate
)
SELECT [Date] = CONVERT(VARCHAR(10),CalanderDate,25)
FROM Calender
OPTION (MAXRECURSION 0)