来自 oracle 数据库的日期和时间
date and time from oracle db
在我的 oracle 数据库中,日期格式类似于“13.10.2015 22:25:56”
但是在我的站点中执行此操作后 select 日期格式正在像这样更改“13-OCT-15” - 没有 hh:mm:ss
<table border='1' align='left' bordercolor='navy' width='13%'>
<tr>
<td align="center">date - number</td>
</tr>
<td align="center">
<?php
$Date_1 = $_POST['Date_1'];
$Date_2 = $_POST['Date_2'];
$conn = oci_connect('login', 'password', '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host)(PORT=port) (CONNECT_DATA=(SERVICE_NAME=service)))');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
//----------------------------------------------------------------------------------
$sql="SELECT DATE, NUMBER FROM DB.RESULT
WHERE (DATE BETWEEN TO_DATE('{$Date_1} 00:00:00', 'YYYY.MM.DD HH24:MI:SS')
AND TO_DATE('{$Date_2} 23:59:59', 'YYYY.MM.DD HH24:MI:SS'))
ORDER BY DATE desc";
$stid = oci_parse($conn, $sql);
oci_execute($stid);
echo "<table border='1' align='left' width='100%' height='100%' bordercolor=navy>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
foreach ($row as $item) {
echo " <td align='center'>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n","</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
echo "</td>"; ?>
in my oracle db date format is like "13.10.2015 22:25:56" but after doing this select in my site date format is changing like this "13-OCT-15" - without hh:mm:ss
Oracle 不会以您看到的格式存储日期。它以 7 个字节的专有格式在内部存储,每个字节存储日期时间值的不同组成部分。
使用 TO_CHAR 和 FORMAT MODEL 以您想要的格式显示日期时间。
例如,
SQL> SELECT TO_CHAR(SYSDATE, 'mm/dd/yyyy hh24:mi:ss') my_format FROM DUAL;
MY_FORMAT
-------------------
10/15/2015 14:19:47
将您的代码修改为:
$sql="SELECT TO_CHAR(DATE, 'mm/dd/yyyy hh24:mi:ss') as "DATE", NUMBER FROM DB.RESULT
WHERE (DATE BETWEEN TO_DATE('{$Date_1} 00:00:00', 'YYYY.MM.DD HH24:MI:SS')
AND TO_DATE('{$Date_2} 23:59:59', 'YYYY.MM.DD HH24:MI:SS'))
ORDER BY DATE desc";
在我的 oracle 数据库中,日期格式类似于“13.10.2015 22:25:56” 但是在我的站点中执行此操作后 select 日期格式正在像这样更改“13-OCT-15” - 没有 hh:mm:ss
<table border='1' align='left' bordercolor='navy' width='13%'>
<tr>
<td align="center">date - number</td>
</tr>
<td align="center">
<?php
$Date_1 = $_POST['Date_1'];
$Date_2 = $_POST['Date_2'];
$conn = oci_connect('login', 'password', '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host)(PORT=port) (CONNECT_DATA=(SERVICE_NAME=service)))');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
//----------------------------------------------------------------------------------
$sql="SELECT DATE, NUMBER FROM DB.RESULT
WHERE (DATE BETWEEN TO_DATE('{$Date_1} 00:00:00', 'YYYY.MM.DD HH24:MI:SS')
AND TO_DATE('{$Date_2} 23:59:59', 'YYYY.MM.DD HH24:MI:SS'))
ORDER BY DATE desc";
$stid = oci_parse($conn, $sql);
oci_execute($stid);
echo "<table border='1' align='left' width='100%' height='100%' bordercolor=navy>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
foreach ($row as $item) {
echo " <td align='center'>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n","</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
echo "</td>"; ?>
in my oracle db date format is like "13.10.2015 22:25:56" but after doing this select in my site date format is changing like this "13-OCT-15" - without hh:mm:ss
Oracle 不会以您看到的格式存储日期。它以 7 个字节的专有格式在内部存储,每个字节存储日期时间值的不同组成部分。
使用 TO_CHAR 和 FORMAT MODEL 以您想要的格式显示日期时间。
例如,
SQL> SELECT TO_CHAR(SYSDATE, 'mm/dd/yyyy hh24:mi:ss') my_format FROM DUAL;
MY_FORMAT
-------------------
10/15/2015 14:19:47
将您的代码修改为:
$sql="SELECT TO_CHAR(DATE, 'mm/dd/yyyy hh24:mi:ss') as "DATE", NUMBER FROM DB.RESULT
WHERE (DATE BETWEEN TO_DATE('{$Date_1} 00:00:00', 'YYYY.MM.DD HH24:MI:SS')
AND TO_DATE('{$Date_2} 23:59:59', 'YYYY.MM.DD HH24:MI:SS'))
ORDER BY DATE desc";