Trouble retrieving DATETIME info from MSSQL

From: Date: Mon, 01 Oct 2001 19:26:04 +0000
Subject: Trouble retrieving DATETIME info from MSSQL
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-12890@lists.php.net to get a copy of this message
Hello, I am having trouble getting data from a DATETIME field in MSSQL 7.0. The data in a general select query look like this: 2001-09-25 14:23:17.000 I can do this in MSSQL: select * from INTERNETLOG where Datetime like %2001% but not this: select * from INTERNETLOG where Datetime like %2001/09/25% or select * from INTERNETLOG where Datetime like %20010925% or select * from INTERNETLOG where Datetime like %2001/09% or select * from INTERNETLOG where Datetime like %14:23% I think it has to do with converting the data type but that's where I'm stuck. from the SQL manual: Pattern Matching with LIKE It is recommended that LIKE be used when you search for datetime values, because datetime entries can contain a variety of dateparts. For example, if you insert the value 19981231 9:20 into a column named arrival_time, the clause WHERE arrival_time = 9:20 cannot find an exact match for the 9:20 string because SQL Server converts it to Jan 1, 1900 9:20AM. However, the clause WHERE arrival_time LIKE ‘%9:20%’ does find it. I've seen a couple of initial questions asked about the same problem but not the answer. Is this a PHP/ODBC issue or just MSSQL? -m

« previous php.db (#12890) next »