将yyyy/mm/dd转换为dd/mm/yyyy hh24:mi:ss



我正在尝试将2016/06/26格式转换为26/06/2016 00:00:00我一直在尝试几乎没有选择错误的错误"无效的名称",有任何想法/建议吗?谢谢

select to_date('2016/05/07 00:00:00','mm/dd/yyyy HH24:MI:SS') from dual

为了将字符串转换为您需要先将其转换为日期的日期。您的问题是您正在尝试格式化字符串而不是日期。因此,对于您的特定情况,将是:

--convert it first to a date
select to_date('2016/05/07 00:00:00','yyyy/mm/dd HH24:MI:SS') 
  from dual
--then convert it to a string in the format you want:
select to_char( to_date('2016/05/07 00:00:00','yyyy/mm/dd HH24:MI:SS'),
                'mm/dd/yyyy HH24:MI:SS' )
  from dual
--since you want it as a date:
--then convert it to a string in the format you want:
select to_date( to_char( to_date('2016/05/07 00:00:00',
                                 'yyyy/mm/dd HH24:MI:SS'),
                         'mm/dd/yyyy HH24:MI:SS' )
                'mm/dd/yyyy HH24:MI:SS' ) 
  from dual

如果您只想将字符串转换为日期,则只需使用我显示的第一个选择即可。感谢@boneist在评论中指出的。

最新更新