Link to home
Start Free TrialLog in
Avatar of sassy168
sassy168

asked on

First day of next month

How do i write a sql to get the first day of next month?

I need the anser to be in this format: '2009-01-01'
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

This should do the trick:
-- as datetime
SELECT DATEADD(mm, 1, DATEDIFF(dd, 0, GETDATE()) - DAY(GETDATE()) + 1)
 
-- shortened string in format requested
SELECT CONVERT(VARCHAR(10), DATEADD(mm, 1, DATEDIFF(dd, 0, GETDATE()) - DAY(GETDATE()) + 1), 120)

Open in new window

Avatar of sassy168
sassy168

ASKER

sorry what about last day of next month??
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
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