简体   繁体   English

进度 SQL:将儒略日期转换为日期时间

[英]Progress SQL : Convert Julian Date into datetime

I working for a client who uses PROGRESS database SQL (i didn't knew this kind of database, so it's my first time that i work on it).我为一个使用 PROGRESS 数据库 SQL 的客户工作(我不知道这种数据库,所以这是我第一次使用它)。 My problem it's all the dates are in Julian-date, and i want to convert them into datetime.我的问题是所有日期都在 Julian-date 中,我想将它们转换为日期时间。 But i haven't found any document or help online that deals with this.但我还没有找到任何处理这个问题的文档或在线帮助。

The only document i found it's: https://knowledgebase.progress.com/articles/Article/How-to-Obtain-a-Julian-Date-in-Progress我发现的唯一文件是: https://knowledgebase.progress.com/articles/Article/How-to-Obtain-a-Julian-Date-in-Progress

But i want to do exactly the opposite.但我想做完全相反的事情。 For example in postgresql:例如在 postgresql 中:

select to_timestamp(column1::text,'J')
from table1

But on PROGRESS it's harder and there is less information and examples than the others databases on the web但在 PROGRESS 上,它比 web 上的其他数据库更难,信息和示例更少

Thank you in advance for your help预先感谢您的帮助

Character特点

In case your Julian date is stored in a field with the character data type, you can use instr to pull it apart and then reassemble it into a timestamp:如果您的 Julian 日期存储在具有字符数据类型的字段中,您可以使用 instr 将其拆开,然后将其重新组合成时间戳:

select 
  -- my character field containing 92182.3966
   descr,
   -- get the year
    floor( cast( left( descr, instr( descr, '.' ) - 1 ) as integer ) / 1000 ) as 'year',
    -- get the day
   mod( cast( left( descr, instr( descr, '.' ) - 1 ) as integer ), 1000 ) as 'day',
   -- get the time
   cast(
    '0' + right( descr, length( descr ) - instr( descr, '.' ) + 1 ) 
      as float
   ) as 'time',
   -- combine all to timestamp
   cast(
      -- get first day of year
      cast(       
        to_char( 
            floor( cast( left( descr, instr( descr, '.' ) - 1 ) as integer ) / 1000 ) 
            + 1900  -- !!! beware
        )
        + '-01-01' 
        as date
      ) 
      -- add days
      + mod( cast( left( descr, instr( descr, '.' ) - 1 ) as integer ), 1000 )

        as timestamp
     )  
     -- add milliseconds
     + cast(
        cast(
        '0' + right( descr, length( descr ) - instr( descr, '.' ) + 1 ) 
        as float
    ) * 86400 * 1000
    as integer
   ) as 'timestamp'  
   
from pub.ddcapp 
where application = 'JULIAN'

This reports that the time is 1992-07-01 09:31:06.24 which is 1 second later than what your link states it was translated from.这报告时间是1992-07-01 09:31:06.24 ,比您的链接声明的翻译时间晚 1 秒。

Decimal十进制

If on the other hand your field is a decimal, it is a lot simpler:另一方面,如果您的字段是小数,则要简单得多:

select 
  -- my decimal field containing 92182.3966
   open_bal,
   -- get the year
    floor( open_bal / 1000 ) as 'year',
    -- get the day
   mod( open_bal, 1000 ) as 'day',
   -- get the time
    open_bal - floor( open_bal ) as 'time',
    
   -- combine all to timestamp
   cast(
      cast( 
        to_char( 
            floor( open_bal / 1000 )
            + 1900  -- !!!
        )
        + '-01-01' 
        as date
      ) 
      + mod( open_bal, 1000 )    
        as timestamp        
    ) 
    + ( open_bal - floor( open_bal ) ) * 86400 * 1000
     as 'timestamp'
   
from pub.ledbal 
where adm_nr = 0

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

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