首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Progress SQL :将Julian日期转换为日期时间

Progress SQL :将Julian日期转换为日期时间
EN

Stack Overflow用户
提问于 2021-05-11 23:26:10
回答 1查看 121关注 0票数 0

我为一个使用进度数据库SQL的客户工作(我不知道这种数据库,所以这是我第一次使用它)。我的问题是所有的日期都是Julian-date,我想把它们转换成datetime。但我没有在网上找到任何与此相关的文档或帮助。

我找到的唯一文档是:https://knowledgebase.progress.com/articles/Article/How-to-Obtain-a-Julian-Date-in-Progress

但我想做的恰恰相反。例如在postgresql中:

代码语言:javascript
复制
select to_timestamp(column1::text,'J')
from table1

但在进展方面,它更难,而且与web上的其他数据库相比,信息和示例更少

预先感谢您的帮助

EN

回答 1

Stack Overflow用户

发布于 2021-05-13 18:33:36

Character

如果您的Julian日期存储在具有字符数据类型的字段中,您可以使用instr将其拆分,然后将其重新组装为时间戳:

代码语言:javascript
复制
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'

这报告时间是1992-07-01 09:31:06.24,这比你的链接声明的翻译时间晚了1秒。

十进制

另一方面,如果你的字段是一个小数,那就简单多了:

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67489810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档