如何在午夜约会 [英] How to get a date at midnight
问题描述
我想知道如何获得 00 小时、00 分和 00 秒的日期.
这个
select to_char(sysdate, 'dd/MM/YYYY HH:mm:ss') from dual;
给出我询问时的日期
如果我不给任何时间:
select to_char(to_date('03/05/2017', 'DD/MM/YYYY'), 'DD/MM/YYYY HH:mm:ss') from dual;
我中午有个约会.
如何在 00:00:00 获得日期(使用 sysdate 或使用 to_date 提供我自己的日期)
谢谢
使用 TRUNC( date_value, format_model )
并省略格式模型(默认为截断到午夜)或使用 格式模型 'ddd'
, 'dd'
或 'j'
:
SELECT TRUNC( SYSDATE) FROM DUAL;
<块引用>
我不给任何时间:
select to_char(to_date('03/05/2017', 'DD/MM/YYYY'), 'DD/MM/YYYY HH:MI:SS') from dual;
我中午有个约会.
不,您将午夜的日期格式化为 12 小时制.
select to_char( to_date('03/05/2017', 'DD/MM/YYYY'), 'DD/MM/YYYY HH:MI:SS PM')
输出 03/05/2017 12:00:00 AM
要获得 24 小时制,您需要在格式模型中使用 HH24
(而不是 HH
或 HH12
,后者是 12-小时时钟):
select to_char( to_date('03/05/2017', 'DD/MM/YYYY'), 'DD/MM/YYYY HH24:MI:SS')
输出 03/05/2017 00:00:00
I would like to know how to get a date with 00 hour, 00 minutes and 00 seconds.
This
select to_char(sysdate, 'dd/MM/YYYY HH:mm:ss') from dual;
gives the date at the time I asked it
If I don't give any hour :
select to_char(to_date('03/05/2017', 'DD/MM/YYYY'), 'DD/MM/YYYY HH:mm:ss') from dual;
I have a date at noon.
How can I get a date (with sysdate or giving my own date with to_date) at 00:00:00
Thank you
Use TRUNC( date_value, format_model )
and either omit the format model (the default is to truncate to midnight) or use one of the format models 'ddd'
, 'dd'
or 'j'
:
SELECT TRUNC( SYSDATE ) FROM DUAL;
I dont give any hour :
select to_char(to_date('03/05/2017', 'DD/MM/YYYY'), 'DD/MM/YYYY HH:MI:SS') from dual;
I have a date at noon.
No, you have the date at midnight formatted with a 12-hour clock.
select to_char( to_date('03/05/2017', 'DD/MM/YYYY'), 'DD/MM/YYYY HH:MI:SS PM')
Outputs 03/05/2017 12:00:00 AM
To get a 24-hour clock you need to use HH24
in the format model (rather than HH
or HH12
which is a 12-hour clock):
select to_char( to_date('03/05/2017', 'DD/MM/YYYY'), 'DD/MM/YYYY HH24:MI:SS')
Outputs 03/05/2017 00:00:00
这篇关于如何在午夜约会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!