dpk
dpk

Reputation: 339

Adding 1 year date and week days in mysql

I have database table as Calendar with LoginDate And LoginDay as columns. I want to Add date and day of the week for next 1 year. I know how to do it for one column but I have to do that for both the columns.

UPDATE timsheetdb.calendar
SET LoginDate = DATE_ADD('2016-02-29', INTERVAL 1 YEAR);

Upvotes: 1

Views: 186

Answers (1)

Mureinik
Mureinik

Reputation: 311808

Frankly, the LoginDay shouldn't even be a column in the table. Since it's just a specific format for LoginDate, you can drop it, and generate it on the fly, using the dayname function, e.g., as part of a view:

CREATE VIEW calendar_view AS
SELECT *, DAYNAME(LoginDate) AS LoginDay
FROM   calendar

If this is not an option, you could use the same function in your update statement:

UPDATE timsheetdb.calendar 
SET    LoginDate = DATE_ADD('2016-02-29', INTERVAL 1 YEAR),
       LoginDay = DAYNAME(LoginDate = DATE_ADD('2016-02-29', INTERVAL 1 YEAR))

Upvotes: 1

Related Questions