Convert 24 Hour time to 12 Hour plus AM/PM indication Oracle SQL

前端 未结 1 1111
我在风中等你
我在风中等你 2020-12-15 06:59

I am required to do the following as an exercise, and I am struggling to find a solution:

Write a SELECT statement that returns these columns from the Invoices table

相关标签:
1条回答
  • 2020-12-15 07:45

    For the 24-hour time, you need to use HH24 instead of HH.

    For the 12-hour time, the AM/PM indicator is written as A.M. (if you want periods in the result) or AM (if you don't). For example:

    SELECT invoice_date,
           TO_CHAR(invoice_date, 'DD-MM-YYYY HH24:MI:SS') "Date 24Hr",
           TO_CHAR(invoice_date, 'DD-MM-YYYY HH:MI:SS AM') "Date 12Hr"
      FROM invoices
    ;
    

    For more information on the format models you can use with TO_CHAR on a date, see http://docs.oracle.com/cd/E16655_01/server.121/e17750/ch4datetime.htm#NLSPG004.

    0 讨论(0)
提交回复
热议问题