0

I want to update date column of the table with dates in the increment of 1 for all rows.

How do I do it in MySQL?

Table: tbl_question_of_the_day Column: date

So the output that I want is:

Row 1: Today

Row 2: Tomorrow

Row 3: Day after tomorrow ...and so on.

There is an ID column as primary key.

Thanks!

0

1 Answer 1

0

If the goal is to have the following:

id date message
1 2021-05-26 There is no spoon.
2 2021-05-27 I know kung fu.
3 2021-05-28 zOMG! A Nokia 8801!
4 2021-05-29 Anything you'd like, Mr. Reagan.
5 2021-05-30 Follow the white rabbit.
6 2021-05-31 Not like this.

... then I would suggest taking a look at the DATE_ADD() function and using the id value as the INTERVAL amount.

3
  • Thanks for this. But how will the Update statement look like? I understand I might have to do some kind of looping I guess.
    – meetpd
    Commented May 26, 2021 at 5:24
  • There is almost no reason to ever do a loop when working with data like this. I would strongly recommend taking a look at Stack Overflow to see how UPDATE statements are generally written, as that site is probably better geared towards these sorts of questions
    – matigo
    Commented May 26, 2021 at 5:30
  • Ok..Thank you for your suggestions.
    – meetpd
    Commented May 26, 2021 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.