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>
    ";  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?