ms sql + dates

i would like to get the first day and last of the month of the previous month, i am using the following code, but would like the time for the startdate be 00:00 and end date 23:59 how can i modify to accomplish.

declare @StartDate datetime,
            @EndDate datetime

select @StartDate = DATEADD(dd,-(DAY(DATEADD(mm,1,GetDate()))-1),DATEADD(mm,-1,GetDate()))
select @EndDate = DATEADD(dd, -DAY(DATEADD(m,1,GetDate())), DATEADD(m,0,GetDate()))
dkilbyAsked:
Who is Participating?
 
_agx_Commented:
Here's one way. There may be a more elegant approach for 2008

declare @StartDate datetime, @EndDate datetime
set @StartDate = dateAdd(m, -1, convert(datetime, convert(varchar(6), getDate(), 112) +'01', 112))
set @endDate = dateAdd(n, -1, dateAdd(m, 1, @startDate))
select @startDate, @endDate

Open in new window

0
 
dkilbyAuthor Commented:
thanks for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.