Link to home
Start Free TrialLog in
Avatar of ryanwh
ryanwhFlag for Canada

asked on

Format a date for 1st day of last month.

I am trying to capture the 1st day of the previous month,  I need the date in the following format so that I can compare it to another date  2011-01-21 00:00:00.000

The code I have that gives me the date of the 1st day of the previous month is (DATEADD(dd,-(DAY(DATEADD(mm,1,GETDATE()))-1),DATEADD(mm,-1,getdate()))) but this has the time component and i need that set to 000...
ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
select DateAdd(month,-1,Convert(datetime, convert (varchar,Year(GETDATE())) + '-'+ convert (varchar,Month(GETDATE())) + '-01'))