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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date diff

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 DATETIME
DECLARE @dd INT,@DD1 INT
SET @dd = DATEPART(dd,DATEADD(day, 30,'2008-03-31'))

SELECT @dd
SET @DD1 = DATEDIFF(day, @dd,DATEPART(dd,GETDATE()))
SELECT @dd1

Result 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 out

Yaman

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-29 : 03:22:30
What do you expect in place of -1?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-04-29 : 03:24:34
DATEPART(dd,GETDATE()) gives you 29

29 - 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]

Go to Top of Page

yaman
Posting Yak Master

213 Posts

Posted - 2009-04-29 : 03:31:18
quote:
Originally posted by khtan

DATEPART(dd,GETDATE()) gives you 29

29 - 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
Go to Top of Page

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 number

Yaman
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-04-29 : 03:32:06
read this http://www.sqlteam.com/article/datediff-function-demystified


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

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 number

Yaman


DECLARE @FinalDate DATETIME
DECLARE @dd INT,@DD1 INT
SET @dd = DATEPART(dd,DATEADD(day, 30,'2008-03-31'))

SELECT @dd
SET @DD1 = ABS(DATEDIFF(day, @dd,DATEPART(dd,GETDATE())))
SELECT @dd1

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -