skip to Main Content

I have a MySQL database using phpmyadmin.
I have a table consisting ID (integer), Status (integer), and Date (timestamp).

For example :

-------------------------------------------
  ID   |    Status   |        Date        
-------------------------------------------
   1   |      1      | 2019-05-10 00:00:00
   2   |      1      | 2019-05-11 00:00:00
-------------------------------------------

I want to change the Status value from 1 into 2 when the SYSDATE is reaching the Date record. How can I do that ?

Thank you 🙂

4

Answers


  1. Try this option:

    UPDATE yourTable
    SET Status = 2
    WHERE CURDATE() >= Date AND Status = 1;
    

    This assumes that your Date column in fact stores just dates. If it stores timestamps, and you only want to flag when the current timestamp exceeds the Date column, then use SYSDATE() instead:

    UPDATE yourTable
    SET Status = 2
    WHERE SYSDATE() >= Date AND Status = 1;
    
    Login or Signup to reply.
  2. You could use

    update  my_table  
    set statys = 2 
    where 
    WHERE CURDATE() >= FROM_UNIXTIME(Date) 
    AND Status = 1;
    
    Login or Signup to reply.
  3. You can:

    1. Create an event on your database and run UPDATE query.

    or

    1. Create a CRON job to run specific PHP file on your server where will be your UPDATE query.

    And set them to run e.g. for every day.

    Login or Signup to reply.
  4. Try This

    Update tablename SET Status = 2 Where CURDATE() >= Date AND Status = 1;
    

    OR

    Update tablename SET Status = 2 Where Date >= NOW()  AND Status = 1;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search