简体   繁体   English

将奇怪的 5 位数转换为正常日期 Oracle SQL

[英]Convert strange 5 digit number to normal Date in Oracle SQL

I have numbers like 42946 in a database column and i want to format it as a normal Date like dd/mm/yyyy .我在数据库列中有类似42946的数字,我想将其格式化为普通日期,如dd/mm/yyyy I was searching a lot but i dont find anything usefull.我搜索了很多,但没有找到任何有用的东西。

I tried to do TO_DATE(<date>,'J') but this doesn't work beacuse i think 42946 is the number of days between today and January 1 of 1900, and this method works only for dates that are between today and January 1 of 4712 BC.我尝试执行TO_DATE(<date>,'J')但这不起作用,因为我认为42946是今天和 1900 年 1 月 1 日之间的天数,并且此方法仅适用于今天和 1 月之间的日期公元前 4712 年的第 1 篇。

I hope you can help me with this.我希望你能帮我解决这个问题。

i think 42946 is the number of days between today and January 1 of 1900我认为 42946 是从今天到 1900 年 1 月 1 日之间的天数

You mean, number of days since 1st of January 1900?你的意思是,自 1900 年 1 月 1 日以来的天数?

If so, you don't have to do much - just add that value to date you specified and you'll get the result.如果是这样,您无需做太多事情 - 只需将该值添加到您指定的日期,您就会得到结果。 Its (result's) datatype is DATE so you can display it any way you want, using the to_char function (or any other option you prefer):它的(结果)数据类型是DATE ,因此您可以使用to_char function(或您喜欢的任何其他选项)以任何方式显示它:

SQL> select date '1900-01-01' + 42946 as result from dual;

RESULT
----------
01.08.2017

SQL>

Example of formatting it:格式化示例:

SQL> select to_char(date '1900-01-01' + 42946, 'dd-mon-yyyy', 'nls_date_language = english') as result from dual;

RESULT
-----------
01-aug-2017

SQL>

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

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