Reputation: 339
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
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