ryanwh
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,GETDA TE()))-1), DATEADD(mm ,-1,getdat e()))) but this has the time component and i need that set to 000...
The code I have that gives me the date of the 1st day of the previous month is (DATEADD(dd,-(DAY(DATEADD(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
select DateAdd(month,-1,Convert(d atetime, convert (varchar,Year(GETDATE())) + '-'+ convert (varchar,Month(GETDATE())) + '-01'))