SQL 如何在oracle sql中获取日期列的时间戳?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24029999/
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
How to get timestamp for date column in oracle sql?
提问by UI_Dev
I am having a table name called "users". It has one column named "logondt" in which it will show only in this format mm:dd:yy
like 04-JUN-14
.
But I need to use select query to find in which time, the user is logged in.
我有一个名为“users”的表名。它有一个名为“logondt”的列,其中它将仅以这种格式显示,mm:dd:yy
例如04-JUN-14
. 但是我需要使用选择查询来查找用户登录的时间。
I tried something like this..
我试过这样的事情..
select logondt from users where logondt between to_date('2014-06-03' ,'yyyy-mm-dd') and to_date('2014-06-03' ,'yyyy-mm-dd') and userid='12345';
Is it possible?
是否可以?
回答by Nishanthi Grashia
Use TO_CHARfunction
使用TO_CHAR函数
SELECT TO_CHAR(LOGONDT , 'DD/MM/YYYY HH:MI:SS') LOGONDT
FROM USERS
WHERE
LOGONDT BETWEEN to_date('2014-06-03' ,'yyyy-mm-dd')
and to_date('2014-06-03' ,'yyyy-mm-dd')
AND USERID = '12345';
To Get in 24 HR format, use
要获得 24 HR 格式,请使用
TO_CHAR(LOGONDT , 'DD/MM/YYYY HH24:MI:SS')