Chad Fender
Chad Fender

Reputation: 23

Have a table that includes startdate and durationminutes. Trying to get that to give new end date in SQL

Title says it all.

Table looks like this

Table: Time
First Column: startdate (shown as yyyy-mm-dd hh:mm:ss)
Second COlumn: durationminute (shown in minutes)

Since the above doesn't give me an end date, I'm trying to create a query which will do that.

I'm assuming this is going to be a dateadd function but I can't get it to work. The durationminutes is a variable to is dependent on that one row so date_add(minutes, 30, startdate) wouldn't work as there is no constant.

I've tried

date_add(days, durationminutes/1440, startdate) 

But am getting a syntax error.

Upvotes: 1

Views: 14

Answers (1)

GMB
GMB

Reputation: 222462

MySQL understands date arithmetics. Assuming that startdate is of date or datetime datatype (as it should be!), you can do:

select t.*,
    startdate + interval durationminute minute as enddate
from time t

Upvotes: 2

Related Questions