简体   繁体   中英

Convert number to Date in Pervasive SQL

I am using Actian SQL Version 12.10.067 and trying to output some values.

When running the following query:

SELECT Artikel, Deb, Datum,(BeginVoorraad + Mutatie)AS Stand 
from "Fust"
where Artikel IN (97955)
ORDER BY Artikel DESC

I get the output:

Artikel Deb    Datum   Stand
97955   200256 41865.0 68.0

Now I would like to change the Datum number(41865.0) to a real date like 22-08-2018.

I hope someone can help me with the right answer!

I am guessing that you want the value convert to the date 2014-08-14 (the value in Excel). If so:

SELECT Artikel, Deb,
       '1899-12-30'::date + Datum * interval '1 day',
       (BeginVoorraad + Mutatie)AS Stand 
FROM "Fust"
WHERE Artikel IN (97955)
ORDER BY Artikel DESC;

The Excel dates are messed up, because it doesn't recognize 1900 as a non-leap year (look it up on Wikipedia).

If the value is subtly different, just change the base date so you get the value you really want.

EDIT:

In Pervasive, I think this does what you want:

dateadd('day', datum, '1899-12-30')

正确答案是

CAST((Datum -2) AS datetime)

you can try this

SELECT Artikel, Deb, cast(Datum as datetime),(BeginVoorraad + Mutatie)AS Stand 
from "Fust"
where Artikel IN (97955)
ORDER BY Artikel DESC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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