Jason
Jason

Reputation: 15335

How to set and ending date value based on begining date with mySQL

I have a table with two fields, date_start & date_end, both are date fields.

date_start currently is populated with various dates. I need to set date_end to 6/30 of the following year.

So if date_start = 2009-03-15 then date_end = 2010-06-30

if date_start = 2010-03-15 then date_end = 2011-06-30

if date_start = 2010-07-01 then date_end = 2011-06-30

Is there a simple way I can go about setting the ending date in a query?

Upvotes: 1

Views: 65

Answers (1)

MatTheCat
MatTheCat

Reputation: 18721

UPDATE table SET date_end=STR_TO_DATE(CONCAT(YEAR(date_start)+1,'-06-30'),'%Y-%m-%d')

?

Upvotes: 3

Related Questions