How to get a date at midnight

前端 未结 2 1073
臣服心动
臣服心动 2021-01-19 10:42

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;


        
相关标签:
2条回答
  • 2021-01-19 11:29

    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 'ffffd', '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

    0 讨论(0)
  • 2021-01-19 11:36

    mm should be replaced with mi for minutes:

    select to_char(to_date('03/05/2017', 'DD/MM/YYYY'), 'DD/MM/YYYY HH:mm:ss') from dual;
    
    0 讨论(0)
提交回复
热议问题