[英]Convert 3 digit input to date format
Even though the business requirement states the input as a "julian" date, it is actually a 3 digit number being passed to the Oracle stored procedure. 即使业务要求将输入的日期指定为“朱利安”日期,它实际上也是一个3位数的数字,传递给Oracle存储过程。 For example, if the input is '001' then I need to convert it to January1 of the current year or if it is 010 convert it to January 10 of the current year etc. How would i do that taking into consideration leap years too?
例如,如果输入为'001',那么我需要将其转换为当年的January1,或者如果将其转换为010,则将其转换为当年的1月10,等等。我还要考虑leap年如何做呢? Please suggest.
请提出建议。 Thank you for your time.
感谢您的时间。
if the three digit number represents the day of the year you could simply use the to_date
function with DDD
, which represents a three digit number which is the day of the year. 如果三位数代表一年中的某一天,则可以简单地将
to_date
函数与DDD
一起使用, DDD
代表三位数,即一年中的某天。
select to_char(to_date(310, 'DDD'),'DD.MM.YYYY') from dual; -- 05.11.2016
select to_char(to_date(001, 'DDD'),'DD.MM.YYYY') from dual; -- 01.01.2016
select to_char(to_date(010, 'DDD'),'DD.MM.YYYY') from dual; -- 10.01.2016
select to_char(to_date(060, 'DDD'),'DD.MM.YYYY') from dual; -- 29.02.2016
you can try this approach. 您可以尝试这种方法。
select to_char(trunc(sysdate, 'YY') + 060 - 1, 'DD/MM/YYYY') as day from dual;
29/02/2016 29/02/2016
select to_char(trunc(sysdate, 'YY') + 010 - 1, 'DD/MM/YYYY') as day from dual;
10/01/2016 2016年10月1日
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.