skip to Main Content

I want to add a date column to an existing table. I only want to add the last date of the month (e.g.30 Apr 2023). How do I do this for all the row? Is this possible?

Date BLa Bla
30 Apr 2023 Cell 2
30 Apr 2023 Cell 4
30 Apr 2023 Cell 6

and so on.

I am using MySQL. Thanks in advance 😀

ALTER TABLE table1
ADD Date Date

INSERT INTO table1 (Date)
VALUES ('2023-04-30')
having row_id =1

2

Answers


  1. You can try:

    UPDATE table1
    SET `Date` = "2023-04-30";
    

    to update all rows with column Date.

    Login or Signup to reply.
  2. You can try next approach:

    -- add new column
    alter table t add column last_of_month date;
    
    -- update the column by last date of currnet month
    update t set last_of_month = last_day(current_date);
    
    -- check 
    select * from t;
    

    Test code here: https://sqlize.online/s/5i

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search