July 27, 2012 at 8:57 am
hi
i want next day function
for example. if i enter 12/31/2008 ,it should give me 01/01/2009
July 27, 2012 at 9:00 am
harri.reddy (7/27/2012)
hii want next day function
for example. if i enter 12/31/2008 ,it should give me 01/01/2009
declare @ThisDay date = '20081231';
select dateadd(dd, 1, @ThisDay) -- returns the next day
July 27, 2012 at 9:00 am
harri.reddy (7/27/2012)
hii want next day function
for example. if i enter 12/31/2008 ,it should give me 01/01/2009
Check out DATEADD() in BOL.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 27, 2012 at 12:37 pm
Step 1 : adds one day to current datetime
SELECT GETDATE()+1 AS NextDay
Step 2 : If only date is required
SELECT CONVERT(DATE,GETDATE()+1) AS NextDay
~ Lokesh Vij
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
July 27, 2012 at 12:48 pm
Lokesh Vij (7/27/2012)
Step 1 : adds one day to current datetime
SELECT GETDATE()+1 AS NextDay
Step 2 : If only date is required
SELECT CONVERT(DATE,GETDATE()+1) AS NextDay
Could just be me, but I'd rather use the dateadd function. It makes explicit what you are doing. Yes, GETDATE() + 1 does imply that you are adding 1 to the current date, but if the column or variable is defined as DATE or DATETIME2 and you try that, you get an error:
declare @TestDate date = '20120726';
select @TestDate + 1;
declare @TestDateTime2 datetime2 = '20120726';
select @TestDateTime2 + 1;
Msg 206, Level 16, State 2, Line 2
Operand type clash: date is incompatible with int
Msg 206, Level 16, State 2, Line 4
Operand type clash: date is incompatible with int
July 27, 2012 at 1:07 pm
Yes agreed. This can only be used for datetime.
I was just trying to show one more way of doing it ๐
~ Lokesh Vij
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
July 30, 2012 at 8:23 am
thx guys
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply