简体   繁体   English

Oracle中的日期格式(0)转换

[英]Date format(0) conversion In Oracle

I am trying to convert the date format stored in my table with a specified format but it is not converting it to the desired format. 我正在尝试将存储在表中的日期格式转换为指定格式,但未将其转换为所需格式。

I have a table having data in format 15-Jan-2016 00:21:06 CEST and 6/19/2019 3:07:01 AM and I have to convert the date into DD-MON-YY hh24:mi:ss am. 我有一个表,其数据格式为CEST 15-Jan-2016 00:21:06和2019/6/19 3:07:01 AM,我必须将日期转换为DD-MON-YY hh24:mi:ss am 。

I am using the below query to format the data. 我正在使用以下查询来格式化数据。

select to_char(to_date(substr(mod,1,20),'DD-MON-YY hh24:mi:ss'),'MM-DD-YYYY HH:MI:SS AM') datetime from test where mod like '%CEST'
union all
select to_char(to_date(mod,'MM-DD-YY hh:mi:ss am'),'MM-DD-YYYY HH:MI:SS AM') datetime from test where mod  not like '%CEST';

It is giving proper output 0 1-15-2016 12:21:06 AM and 0 6-19-2019 03:07:01 AM. 它会给出正确的输出0 1-15-2016 12:21:06 AM和0 6-19-2019 03:07:01 AM。 But I don't want the 0 coming before the month. 但是我不希望0出现在本月之前。 Is there any specifed date format for removing the 0? 是否有指定的日期格式可以删除0?

Apply the fm format mask modifier. 应用fm格式掩码修饰符。 See res_2 : 参见res_2

SQL> select to_char(sysdate, 'mm-dd-yyyy') res_1,
  2         to_char(sysdate, 'fmm-dd-yyyy') res_2
  3  from dual;

RES_1      RES_2
---------- ----------
08-13-2019 8-13-2019

SQL>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM