将HTML日期转换为Oracle日期

时间:2014-04-12 03:12:04

标签: php oracle date

我有一个html输入类型日期,我想插入到oracle日期。如何将转换成oracle日期?到目前为止,我有这个,

<label><span>DUE DATE</span>
    <input id="duedate" type="date" name="duedate" size="10" maxlength="10" value="" />         
</label>

<label><span>&nbsp;</span>
    <input class ="button" type="submit" name="submit" value="Submit!" />
</label>
</form>
  
 <?php
  // If the submit button has been pressed...

  if (isset($_POST['submit']))
  {    
    $s = oci_parse($conn, "INSERT INTO TIMESPAN
         (HEAD_MARK, INIT_DATE, DUE_DATE, SUBCONT_ID, REMARKS)
          VALUES (:hMark, SYSDATE, :dueDate, :subcontId, :remarks)");

    oci_bind_by_name($s, ":hMark", $_POST['headmark']);
    oci_bind_by_name($s, ":dueDate", $_POST['duedate']);
    oci_bind_by_name($s, ":subcontId", $_POST['subcontid']);
    oci_bind_by_name($s, ":remarks", $_POST['remarks']);

    $result = oci_execute($s, OCI_DEFAULT);

    if ($result)
        {
            oci_commit($conn); // COMMIT TRANSACTION
            echo 'INSERT TO DB COMPLETED';
        } else {
            oci_rollback($conn); // ROLLBACK INSERTION
            $m = oci_error($s);
            echo "ERROR OCCURED".$m;
        }
    oci_close($conn);

2 个答案:

答案 0 :(得分:0)

假设dd-MMM-yy格式,那么这样的事情应该有效:

oci_bind_by_name($s, ":dueDate", strtoupper(date('d-M-y', strtotime($_POST['duedate']))));

答案 1 :(得分:0)

要将“字符串”日期放入Oracle中的“日期”变量类型,您需要使用TO_DATE()pl / sql命令:http://www.techonthenet.com/oracle/functions/to_date.php

TO_DATE($_POST['duedate'], 'mm/dd/yyyy')