0

Ok so I have an obnoxious problem to solve here and im stumped.

I have a MySQL table with basically this structure

id  transdate  startdate   enddate      unit1  unit1price   unit2   unit2price

1   2014-07-31   2014-10-25  2014-10-29   22     25.00        27      25.00

What I need to do is create another column that is totaldays which calculates the number of days between startdate and enddate.

How do I do this?

Thanks so much

Donal
  • 31,121
  • 10
  • 63
  • 72

2 Answers2

0

You may try something like:

SELECT datediff(enddate, startdate)...

More info here: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff

MillaresRoo
  • 3,808
  • 1
  • 31
  • 37
0

--create the column

alter table YourTableName
add column daysdiff int;

--update the new column with appropriate computation

update YourTableName
set daysdiff = datediff(enddate, startdate);
Eric
  • 4,201
  • 5
  • 27
  • 36