Currently I'm trying to select a datetime column from two date columns. I'm having the following situation:
FROMDATE
column which contains dates without time, e.g. 08-01-2017 00:00:00
FROMTIME
column which contains times without a date, e.g. 01-01-1899 13:50:00
Now I want to select both within one column, e.g. SELECT (<what ever>) as FROMDATETIME ...
Expected result: 08-01-2017 13:50:00
But I'm not able to extract the date and time parts and add them together as a datetime
.
Spoken in a kind of meta sql: select (date(FROMDATE) + time(FROMTIME)) as FROMDATETIME
.
I've tried a lot with TO_CHAR
and TO_DATE
but was not able to get the expecting result.
Combine date and time with formula in Excel There is a very simple formula that can quickly help you combine date column and time column into one. Tip: You also can use this formula =A2+B2 and then format the result cells as date and time formatting.
To combine date and time column into a timestamp, you can use cast() function with concat(). select cast(concat(yourDateColumnName, ' ', yourTimeColumnName) as datetime) as anyVariableName from yourTableName; In the above concept, you will use cast() when your date and time is in string format.
Here you go:
SELECT TO_DATE(TO_CHAR(t.fromdate,'dd-mm-yyyy') ||
' ' ||
TO_CHAR(t.fromtime,'hh24:mi:ss'),'dd-mm-yyyy hh24:mi:ss') as full_date_col
FROM YourTable t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With