简体   繁体   English

SQL查询将2019/05/21 00:00:00格式转换为19-JUN-19(即DD-MON-YY)

[英]SQL Query to Convert 2019/05/21 00:00:00 format to 21-JUN-19(i.e., DD-MON-YY)

I have a date format "2019/05/21 00:00:00" and I need to convert this into "21-JUN-19" using SQL. 我的日期格式为“ 2019/05/21 00:00:00”,我需要使用SQL将其转换为“ 21-JUN-19”。 How can I convert this? 我该如何转换呢?

Assuming that the source value is a string, then 假设源值为字符串,则

  • first convert it to a date (using to_date , with appropriate format mask) 首先将其转换为日期(使用to_date ,使用适当的格式掩码)
  • then convert it to a string (using to_char , again with appropriate format mask) 然后将其转换为字符串(使用to_char ,再次使用适当的格式掩码)

By the way, why are you converting 2019/ 05 /21 into jun ? 顺便说一句,你为什么将2019/05/21形成 It can be done, no problem ( ADD_MONTHS does that), just wondering whether you did it intentionally or by mistake. 可以做到,没问题( ADD_MONTHS做到这一点),只是想知道您是故意还是错误地做到了。

SQL> select to_char(to_date('2019/05/21 00:00:00', 'yyyy/mm/dd hh24:mi:ss'), 'dd-mon-yy') result from dual;

RESULT
---------
21-may-19

SQL>

You can use substr() and to_date() : 您可以使用substr()to_date()

select to_date(substr('2019/05/21 00:00:00', 1, 10), 'YYYY/MM/DD')
from dual;

暂无
暂无

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

相关问题 如何在 oracle sql 中将 Mon Dec 21 00:00:00 EST 2020 转换为 dd/mm/yyyy - How to convert Mon Dec 21 00:00:00 EST 2020 into dd/mm/yyyy in oracle sql SQL:是否可以将 dd-mon-yy 转换为一天中的某个时间? - SQL: Is it possible to convert dd-mon-yy to a time of day? 如何将日历转换为DD-Mon-YY格式和奇怪的查询结果 - How to convert a Calendar into the DD-Mon-YY format and weird query results Oracle SQL将日期格式从DD-Mon-YY转换为YYYYMM - Oracle SQL convert date format from DD-Mon-YY to YYYYMM 如何在 Snowflake SQL 中将日期时间“2022 年 5 月 30 日 9:30PM”转换为“2022-05-30 21:30:00”? - How to convert a datetime ''May 30 2022 9:30PM" to this "2022-05-30 21:30:00" in Snowflake SQL? 在 oracle 中,如何创建检查时间是否在 10:00:00 和 21:00:00 之间的检查约束? - In oracle, how do I create a check constraint that checks if the time is between 10:00:00 and 21:00:00? 如何在SQL Server R2中将日期时间格式化为dd-MMM-yy(或dd-mon-yy)? - How can I format a datetime in SQL Server R2 to dd-MMM-yy (or dd-mon-yy)? 如何将 SQLite 中的 0:00:00 转换为 00:00:00 时间格式? - How to convert 0:00:00 to 00:00:00 time format in SQLite? 将秒转换为“00:00:00”格式 - SQL Server - Convert seconds to '00:00:00' format - SQL Server 将日期时间转换为日期字符串,从 2019-05-02 12:00:00 到 2019-05-02 - to convert datetime into date string from 2019-05-02 12:00:00 to 2019-05-02
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM