php 如何使用php date函数从oracle日期字段中选择日期和时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14028063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:27:33  来源:igfitidea点击:

How to select date and time from oracle date field using php date function

phpsqloracle

提问by hsuk

How to take the time from date stored as 12/25/2012 5:12:05 AM .

如何从存储为 12/25/2012 5:12:05 AM 的日期开始计算时间。

date('l F j, Y, g:i a',strtotime($last_login_details[FL_DATETIME]));

This above function returned time as 12:00 am which should return 5:12AM.

上述函数返回时间为 12:00 am,应该返回 5:12AM。

FL_DATETIME has datatype DATE.

FL_DATETIME 具有数据类型 DATE。

On database, the value is being stored like this :

在数据库上,该值的存储方式如下:

   12/25/2012 5:12:05 AM

回答by Sean

According to the docs - http://docs.oracle.com/cd/B19306_01/server.102/b14220/datatype.htm#i1847-

根据文档 - http://docs.oracle.com/cd/B19306_01/server.102/b14220/datatype.htm#i1847-

For input and output of dates, the standard Oracle date format is DD-MON-YY

对于日期的输入输出,标准的Oracle日期格式为DD-MON-YY

That is most likely why $last_login_details[FL_DATETIME]is echoing 25-DEC-12

这很可能$last_login_details[FL_DATETIME]是回声的原因25-DEC-12

Try changing your query using TO_CHAR()

尝试使用更改您的查询 TO_CHAR()

SELECT TO_CHAR(FL_DATETIME, 'MM/DD/YYYY HH24:MI:SS A.M.') AS FL_DATETIME ...

see http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html#dateformat

http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html#date格式

回答by hsuk

Solved my problem by :

通过以下方式解决了我的问题:

SELECT TO_CHAR(FL_DATETIME, 'DD.MM.YYYY:HH24:MI:SS') FROM "FMS_LOG" 

回答by Sebastian Frohm

First of all, in my opinion, you should be storing all dates as unix timestamps. This makes it lot easier for you to do searches against times, and removes any inconsistencies that may arise from date string manipulation.

首先,在我看来,您应该将所有日期存储为 unix 时间戳。这使您可以更轻松地根据时间进行搜索,并消除可能因日期字符串操作而引起的任何不一致。

Second, I tested your code; it looks to be OK from what I can tell. Echo out what you are getting in the $last_login_details[FL_DATETIME] variable. The issue may lie in the variable assignment, and not the date string manipulation.

其次,我测试了你的代码;据我所知,它看起来没问题。回显您在 $last_login_details[FL_DATETIME] 变量中得到的信息。问题可能在于变量赋值,而不是日期字符串操作。

Hope that helps!

希望有帮助!