DotDragnet
May 24, 2012, 05:10:05 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: MSSQL date search  (Read 229 times)
Mr Anderson
DDN Contribs
Hero Member
*****
Posts: 2267



ap4a.uk ap4a
View Profile WWW Awards
« on: June 20, 2011, 08:25:41 AM »

I'm trying to get a date search working with MSSQL and for some reason it's not returning any results. I'm not sure if the SQL for MSSQL for date searches should differ from MySQL?

The code I'm trying to use is:

Code:
SELECT StartTimeStamp, Duration, CallDirection, ExternalNumber, Filename FROM IpPbxCDR.dbo.CFData
WHERE ExternalNumber = 'xyz' AND StartTimeStamp >= '11-06-01' AND StartTimeStamp <= '11-06-07'
ORDER BY StartTimeStamp DESC

The StartTimeStamp is stored in the DB as YY-MM-DD HH:MM:SS and is the type timestamp. I'm also using PHP so using ADODB to connect (I'm not sure if that makes a difference).
 
Any suggestions welcome.
Logged

samhs
Administrator
Hero Member
*****
Posts: 1713



View Profile WWW Awards
« Reply #1 on: June 20, 2011, 09:15:08 AM »

use datediff() and compare for a positive (or negative) number instead of > or < - I can't ever get less than or greater than to work consistently with date comparisons.
Logged

Loose adj a not held together; not fastened or firmly fixed in place
Lose verb to misplace something. To fail to keep or obtain something, especially because of a mistake, carelessness, etc.
---
Blog: www.ohwrite.co.uk
Twitter: www.twitter.com/samhs
Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« Reply #2 on: June 20, 2011, 10:21:55 AM »

The thing I've found with dates is that it can be a bit funny if you don't include a time. I've not really found a reliable way to use date comparisons myself, so I might try samhs' suggestion above next time I have some troubles.
Logged

Mr Anderson
DDN Contribs
Hero Member
*****
Posts: 2267



ap4a.uk ap4a
View Profile WWW Awards
« Reply #3 on: June 20, 2011, 01:07:19 PM »

The thing I've found with dates is that it can be a bit funny if you don't include a time. I've not really found a reliable way to use date comparisons myself, so I might try samhs' suggestion above next time I have some troubles.

Give it a go, it's worked for me smile

use datediff() and compare for a positive (or negative) number instead of > or < - I can't ever get less than or greater than to work consistently with date comparisons.

Cheers Sam, that saved me a headache big grin
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!