doujuanju3076 2014-06-21 05:56 采纳率: 0%
浏览 41
已采纳

使用带有ODBC的ms访问在PHP中格式化日期

I'm converting my ASP CLASSIC site to PHP. The site uses MS Access as database and using ODBC to connect with Databse. i'm stuck with the date formatting.

I used to Format Dates in asp as follows:

select U_ID, Trans_Code, Format(Due_Date, 'dd-mmm-yyyy') AS Due_Date

Used the same Format function in PHP but it returns error.

Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Circular reference caused by alias 'Due_Date' in query definition's SELECT list., SQL state S1000 in SQLExecDirect in C:\wamp\www\files.php on line 28

Then i changed the alias to DDATE the error disappears and data returns without Formatting.

I have also tried the non-sql way, but its also returns error.

Here's the date_format function i used.

echo "<td>". Date_Format($DueDate,"d.m.y") ."</td>
";

Returns this error:

Warning: date_format() expects parameter 1 to be DateTime,

Also tried this:

echo "<td>". Date_Format(DateTime($DueDate,"d.m.y")) ."</td>
";

Any help would be much appreciated . . . :)

  • 写回答

1条回答 默认 最新

  • duanjiao5543 2014-06-21 06:58
    关注

    I Fixed the errors :)

    Thanks to S. Ahn for suggesting this:

    Assign the result from the query to a datetime object first, and then format it

    Create the datetime object first

    $DueDate=date_create(odbc_result($rs,"ddate"));
    

    And then formatted it.

    echo "<td>". date_format($DueDate,"j-F-Y") ."</td>
    ";  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)