【问题标题】:Formating an Oracle timestamp with PHP使用 PHP 格式化 Oracle 时间戳
【发布时间】:2015-11-28 20:24:44
【问题描述】:

我想用 php 将日期和时间与在 oracle 中检索到的时间戳分开,但它不起作用。我试图分开日期和工作,之后我必须分开时间,但我得到了空的时间戳。

$db = $row['CREATEDATE']; // CREATEDATE=03-SEP-15 12.55.17.000000 PM

echo 'db...'.(string)$db."<br/>";
$timestamp = strtotime((string)$db);
echo 'timestamp...'.$timestamp."<br/>";
echo date("m-d-Y", $timestamp); 

【问题讨论】:

  • 你得到所有“回声”的空字符串吗?如果没有,为什么不让我们看看 $row 变量的实际内容?
  • $db 不是字符串?以及您需要的日期和时间格式是什么?
  • 我已经提到了 CREATEDATE 的值

标签: php oracle date time timestamp


【解决方案1】:

将您收到的列数据转换为字符串,并将其转换为日期时间。然后您可以对其进行所有其他格式设置。

$db = $row['CREATEDATE'];         //$db need to be converted to string type
$datetime = new DateTime((string)$db);   //I expect (string)$db will considered as a string 
$date =  $datetime->format('Y M d');   //convert to date 
$time = $datetime->format('H:i:s');    //convert to time

【讨论】:

    【解决方案2】:
    $select_stmt = "select to_char(ENDTIME,' hh24:mi:ss') AS CHENG,to_char(RESERVETIME,' hh24:mi:ss') AS CHENG2 FROM RESERVATION WHERE RESERVATIONSTATUS='RENTING' AND RESERVATIONFACILITY = '".$_SESSION['cno']."'"; 
    $stid = oci_parse($con, $select_stmt); 
                            oci_execute($stid); 
    
                            while ($row = oci_fetch_assoc($stid))
                            {
    
                                $datt=$row["CHENG"];
                                $datt2=$row["CHENG2"];
                            }
    

    【讨论】:

    猜你喜欢
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多