Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add timestaps columns numeric columns as an hour

I have to following table called my_table.

| date                     |numeric_data| new_date
|: -------- |: --------------:|:
| 2019-04-16 00:00:00.0    | 11         |2019-04-16 11:00:00.0 
| 2019-04-15 00:00:00.0    | 13         |2019-04-16 13:00:00.0 
select date+ interval to_char(numeric_data) hour from my_table

but it does not works

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the NUMTODSINTERVAL function:

SELECT date_column + NUMTODSINTERVAL(numeric_data, 'HOUR') AS new_date
FROM   my_table

or you can add a multiple of INTERVAL '1' HOUR:

SELECT date_column + numeric_data * INTERVAL '1' HOUR AS new_date
FROM   my_table

or you can add fractions of days:

SELECT date_column + numeric_data/24 AS new_date
FROM   my_table

Which, for the sample data:

CREATE TABLE my_table ( date_column, numeric_data ) AS
SELECT DATE '2019-04-16', 11 FROM DUAL UNION ALL
SELECT DATE '2019-04-15', 13 FROM DUAL;

All output:

NEW_DATE
2019-04-16T11:00:00
2019-04-15T13:00:00

fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading