php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42166 oci8 functions don't retrieve correct date from tables
Submitted: 2007-08-01 11:54 UTC Modified: 2016-03-08 01:04 UTC
From: sven dot goldt dot extern at hvb dot de Assigned: sixd (profile)
Status: Not a bug Package: OCI8 related
PHP Version: 5.2.3 OS: Windows XP
Private report: No CVE-ID: None
 [2007-08-01 11:54 UTC] sven dot goldt dot extern at hvb dot de
Description:
------------
When you want to select a column from a table whose type is "DATE" then php truncates the value so that you only get the day but not the time from it that mean no hours, no minutes and no seconds.

Reproduce code:
---------------
$query="select datefield from sometable";

$conn = oci_connect("user", "pass", "//dbserver:1521/HVSQP0");
$stmt = oci_parse($conn, $query);
oci_execute($stmt);

while ($result = oci_fetch_row($stmt)) { 
print_r($result); print "<br>\n"; 
}
...

Expected result:
----------------
Something like 01.08.2007 13:45:28




Actual result:
--------------
you get only 01.08.2007.

The only workaround i found so far is to change the query to
"select TO_CHAR(datefield,'DD.MM.YYYY HH24:MI:SS') from sometable".

Then you get what you expect.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-01 14:57 UTC] sixd@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

----------------------------------------
The default format of date strings returned to PHP depends on Oracle
settings. Other tools like SQL*Plus will also have the same display
format you see.

You can change the default format by one or all of:

(i) setting environment variables like NLS_LANG or NLS_DATE_FORMAT in the shell that starts the web server or PHP process
(ii) Executing a command like "alter session set nls_date_format='DD.MM.YYYY HH24:MI:SS'" soon after connecting in PHP
(iii) Using to_char() in each query
----------------------------------------

 [2016-03-08 01:04 UTC] sixd@php.net
-Package: Oracle related +Package: OCI8 related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 22:01:28 2024 UTC