TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
List of dates between two dates
Manoj Sevda
Dec 14, 2011
11.9
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
List of dates between two dates.
declare @stdt datetime
,@enddt datetime
select @stdt = '2012-01-01'
,@enddt = '2012-12-31'
select ROW_NUMBER() OVER (ORDER BY dateadd(day, nu.number, @stDt)) AS 'RowNumber', dateadd(day, nu.number, @stDt)as mDate, DATENAME(DW, dateadd(day, nu.number, @stDt)) as mDay,
DATENAME(month,dateadd(day, nu.number, @stDt)) as mMonth
from master..spt_values nu --Any Table of consecutive integers
left outer join sysobjects o --YourTable
on o.crdate = dateadd(day, nu.number, @stDt)
where nu.type = 'p'
and nu.number <= datediff(day, @stDt, @endDt)
group by dateadd(day, nu.number, @stDt)
order by mDate
list of dates between two dates
Next Recommended Reading
Number of weeks between two dates in sql