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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DateDiff in Minutes

Author  Topic 

latture
Starting Member

24 Posts

Posted - 2013-03-06 : 17:30:01
Hey, I think this is pretty simple and it should work but it doesn't. Any clue to why would be very helpful.

select DATEDIFF(mi,i.INVDATE,i.OUTFORDELIVERY) NumBtwFinNOut

Thanks.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2013-03-06 : 18:00:57
What doesn't work about it? All I can see is that you are missing a FROM clause.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-06 : 18:01:48
What does it do? Does it give the wrong result or is it returning an error message, or is it doing something else? The syntax looks right, and assuming that INVDATE and OUTFORDELIVERY columns are of type datetime, datetime2, or smalldatetime, it should work.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-06 : 23:26:42
only issue i can see if one of columns being not having date values in proper format and statement throwing out of range error.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

latture
Starting Member

24 Posts

Posted - 2013-03-07 : 08:03:53
I get a result of 0. I didn't put rest of the statment since those work. It's just this that doesn't. I think visakh16 could be right. I'm going to check out the format thing.

Thanks!
Go to Top of Page

latture
Starting Member

24 Posts

Posted - 2013-03-07 : 08:23:37
Ok. I'm getting the same freakin result. I've tried different variations of convert and cast... Here is what I have now. I'm still just getting 0 as a result.

DATEDIFF(mi,CONVERT(nvarchar(30),i.INVDATE,126),CONVERT(nvarchar(30),i.OUTFORDELIVERY,126)) NumBtwFinNOut

I've also tried datetime instead of nvarchar.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2013-03-07 : 08:36:49
What are the data types of INVDATE and OUTFORDELIVERY? Please provide sample values for each field that are not producing the results that you expect.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

latture
Starting Member

24 Posts

Posted - 2013-03-07 : 08:58:47
Sorry guys. I just realized that there is nothing wrong with the statement. They both had the same value so of course the result would be 0... I'm an idiot. I know. You don't have to rub it in...
Go to Top of Page
   

- Advertisement -