SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DateDiff in Minutes
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

latture
Starting Member

24 Posts

Posted - 03/06/2013 :  17:30:01  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 03/06/2013 :  18:00:57  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3578 Posts

Posted - 03/06/2013 :  18:01:48  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 03/06/2013 :  23:26:42  Show Profile  Reply with Quote
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 - 03/07/2013 :  08:03:53  Show Profile  Reply with Quote
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 - 03/07/2013 :  08:23:37  Show Profile  Reply with Quote
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.

Edited by - latture on 03/07/2013 08:28:23
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 03/07/2013 :  08:36:49  Show Profile  Reply with Quote
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 - 03/07/2013 :  08:58:47  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000