我为一个使用进度数据库SQL的客户工作(我不知道这种数据库,所以这是我第一次使用它)。我的问题是所有的日期都是Julian-date,我想把它们转换成datetime。但我没有在网上找到任何与此相关的文档或帮助。
我找到的唯一文档是:https://knowledgebase.progress.com/articles/Article/How-to-Obtain-a-Julian-Date-in-Progress
但我想做的恰恰相反。例如在postgresql中:
select to_timestamp(column1::text,'J')
from table1但在进展方面,它更难,而且与web上的其他数据库相比,信息和示例更少
预先感谢您的帮助
发布于 2021-05-13 18:33:36
Character
如果您的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'这报告时间是1992-07-01 09:31:06.24,这比你的链接声明的翻译时间晚了1秒。
十进制
另一方面,如果你的字段是一个小数,那就简单多了:
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 = 0https://stackoverflow.com/questions/67489810
复制相似问题