Mike Pala Mike Pala - 1 month ago 11
SQL Question

adding a VARCHAR to DATE as MINUTES

I'm pretty sure this is an easy one for you guys but it's driving me crazy.
I have a column with dates in a "YYYY-MM-DD" format and a column with small intergers values between 0 and 29. So I want to add the 2 columns together and get something like this:

Date | INT | NEW timestamp
2016-01-01 | 2 | 2016-01-01 00:02:00
2016-10-15 | 21 | 2015-10-15 00:21:00


so I tried the obvious like:

"Date" + "INT" as "NEW timestamp"


and stuff like

VARCHAR_FORMAT("INT",'MI')


or even

VARCHAR_FORMAT("Date",'YYYY-MM-DD HH24:MI:SS') + VARCHAR_FORMAT("INT",'MI')


but keep getting errors. I am doing this in dashDB

Answer

One option is to use:

select add_minutes(cast("date" as timestamp),"int") from yourTable

Another simple version is:

select cast("date" as timestamp) + "int" minutes from yourTable