Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
yaman
Posting Yak Master
213 Posts |
Posted - 2009-04-29 : 03:16:48
|
| Sir , data difference come in negative number .I want sir Date diffenence come in Positive Numeber .DECLARE @FinalDate DATETIMEDECLARE @dd INT,@DD1 INTSET @dd = DATEPART(dd,DATEADD(day, 30,'2008-03-31'))SELECT @ddSET @DD1 = DATEDIFF(day, @dd,DATEPART(dd,GETDATE())) SELECT @dd1Result is :30-1 ( This is Not correct ) OR SELECT DATEDIFF(mm,GETDATE(),(DATEADD(day,30,'2005-12-12'))),getdate() Result is :- -39 2009-04-29 12:48:53.750-39 is not correct Pls help me outYaman |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-29 : 03:22:30
|
| What do you expect in place of -1?MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-04-29 : 03:24:34
|
DATEPART(dd,GETDATE()) gives you 2929 - 30 gives you -1. That's correct from the point of datediff.What do you want actually ?please refer to the Books On Line on more details on datediff() KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
yaman
Posting Yak Master
213 Posts |
Posted - 2009-04-29 : 03:31:18
|
quote: Originally posted by khtan DATEPART(dd,GETDATE()) gives you 2929 - 30 gives you -1. That's correct from the point of datediff.What do you want actually ?sir I want my result come with Positive number not in Negative number
Yaman |
 |
|
|
yaman
Posting Yak Master
213 Posts |
Posted - 2009-04-29 : 03:31:52
|
[quote]Originally posted by madhivanan What do you expect in place of -1?Result should be in Positive numberYaman |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-29 : 03:45:33
|
quote: Originally posted by yaman [quote]Originally posted by madhivanan What do you expect in place of -1?Result should be in Positive numberYaman
DECLARE @FinalDate DATETIMEDECLARE @dd INT,@DD1 INTSET @dd = DATEPART(dd,DATEADD(day, 30,'2008-03-31'))SELECT @ddSET @DD1 = ABS(DATEDIFF(day, @dd,DATEPART(dd,GETDATE())))SELECT @dd1MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|