如何查询日期格式YYYY-MM-dd HH-MM-ss? [英] How to query the date format YYYY-MM-dd HH-MM-ss?

查看:347
本文介绍了如何查询日期格式YYYY-MM-dd HH-MM-ss?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用以下格式查询日期:

How to query the date with the format :

02/13/2013 12:05:48

02/13/2013 12:05:48

select * 
from TOTAL_SUBS 
where TIME BETWEEN TO_DATE('2013-13-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS') 
AND TO_DATE('2013-12-14 00:00:00', 'SYYYY-MM-DD HH24:MI:SS');

我已经尝试过使用该代码,但是从日期算起我所期望的只是02/13/2013,结果没有时间"12:05:48"出现.

I have try with that code but what i expected from the date only came out the 02/13/2013, There is no Time "12:05:48" came out in the result.

推荐答案

EDIT :建议对需求格式进行to_char(),因为在您运行查询的所有地方NLS_DATE_FORMAT可能都不相同!

EDIT: It advisable to do to_char() to requirement format, as the NLS_DATE_FORMAT may not be same everywhere you run your Query!

如果您要更改NLS,请执行此操作.

If, at all you want to change NLS, please do this.

alter session set nls_date_format='MM/DD/YYYY HH24:MI:SS';

最后,在选择中进行TO_CHAR()转换.实际上,当您想要以期望的格式打印(参见)DATE数据类型时,请使用此格式.

Finally, a TO_CHAR() conversion in the select. Actually, when you want print(see) a DATE datatype in the format you expect, use this.

select * , TO_CHAR(TIME,'MM/DD/YYYY HH24:MI:SS') my_datetime
from TOTAL_SUBS 
where TIME BETWEEN TO_DATE('2013-02-13 00:00:00', 'SYYYY-MM-DD HH24:MI:SS') 
AND TO_DATE('2013-12-14 23:59:59', 'SYYYY-MM-DD HH24:MI:SS');

编辑了月份和时间戳,直到mdnight为止.希望这会有所帮助!

Edited the month and the timestamp to include till mdnight. Hope this helps!

这篇关于如何查询日期格式YYYY-MM-dd HH-MM-ss?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆