ryann
asked on
T-Sql change month and day
I need to convert a datetime field to the 1st day of the next month. My sql below
works to change the day or month but I want the month and day changed in one statement. Thanks.
declare @newdate datetime,
@olddate datetime
set @olddate = '2015-05-10' -- want this to be '2015-06-01' as @newdate
set @newdate = DATEADD(m,1,@olddate) ---adds 1 to month
set @newdate = dateadd(dd, -DAY(@olddate) + 1, @olddate) --sets day to 1
select @olddate,
@newdate
works to change the day or month but I want the month and day changed in one statement. Thanks.
declare @newdate datetime,
@olddate datetime
set @olddate = '2015-05-10' -- want this to be '2015-06-01' as @newdate
set @newdate = DATEADD(m,1,@olddate) ---adds 1 to month
set @newdate = dateadd(dd, -DAY(@olddate) + 1, @olddate) --sets day to 1
select @olddate,
@newdate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER