将24小时的时间转换为12小时加AM / PM指示Oracle SQL [英] Convert 24 Hour time to 12 Hour plus AM/PM indication Oracle SQL
问题描述
我需要执行以下操作,我正在努力寻找解决方案:
I am required to do the following as an exercise, and I am struggling to find a solution:
编写一个SELECT语句,从发票表中返回这些列:
Write a SELECT statement that returns these columns from the Invoices table:
invoice_date列
The invoice_date column
使用TO_CHAR函数返回具有完整日期和时间的invoice_date列,包括24小时制四位数的年份
Use the TO_CHAR function to return the invoice_date column with its full date and time including a four-digit year on a 24-hour clock
使用TO_CHAR函数返回具有完整日期和时间的invoice_date列,其中包含一个四位数的年份一个12小时的时钟,一个am / pm指标。
Use the TO_CHAR function to return the invoice_date column with its full date and time including a four-digit year on a 12-hour clock with an am/pm indicator.
使用CAST函数将invoice_date列返回为VARCHAR2(10)
Use the CAST function to return the invoice_date column as VARCHAR2(10)
我可以得到的是:
select invoice_date, to_char(invoice_date, 'DD-MM-YYYY HH:MM:SS') "Date 24Hr"
from invoices
这是我的前两列,但是我无法确定任何方式来选择第三列。
任何帮助都会很棒,谢谢。 (是的,这是从我的学校教科书)
Which gets my first two columns, however I can't figure out any way to select the third column. Any help would be great, thanks. (And yes, this is from my school textbook)
推荐答案
对于24小时的时间,你需要使用 HH24
而不是 HH
。
For the 24-hour time, you need to use HH24
instead of HH
.
对于12小时的时间, AM / PM指标写为 AM
(如果您想要结果中的期间)或 AM
(如果你't)。例如:
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
;
有关格式模型的更多信息,可以使用 TO_CHAR
,请参阅 http://docs.oracle.com /cd/E16655_01/server.121/e17750/ch4datetime.htm#NLSPG004 。
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.
这篇关于将24小时的时间转换为12小时加AM / PM指示Oracle SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!