1

I have sent_date and status column in my database table.currently status of the post is = Sent/Received. All I want to change the status = Aborted after 5days automatically.

What I tried:

CREATE EVENT reset ON SCHEDULE EVERY 1 day DO
    update barter_proposals 
       set proposal_status="Aborted"
     WHERE `sent_date`>=DATE_ADD( CURDATE(), INTERVAL 1 day )
       AND proposal_status = "Sent/Received"---------Not worked



CREATE EVENT rot ON SCHEDULE EVERY 1 day DO 
    update barter_proposals 
       set proposal_status="Aborted"
     WHERE DATE_ADD(sent_date, INTERVAL 1 day )>=NOW()
       AND proposal_status = "Sent/Received"---------Not worked



CREATE EVENT rot ON SCHEDULE EVERY 1 day DO 
    update barter_proposals 
       set proposal_status="Aborted"
     WHERE sent_date=CURDATE()
       AND proposal_status = "Sent/Received"-----------Not Worked

How can I update the status automatically after 5 days? sent_date can be anything.

If sent_date is 26/03/2018 then on 01/04/2018, the status should update to Aborted automatically. How can I write the logic?

halfer
  • 19,824
  • 17
  • 99
  • 186
chetan kambli
  • 794
  • 5
  • 21
  • Please confirm that event scheduler is running see here for detail https://stackoverflow.com/questions/16767923/mysql-event-not-working – P.Salmon Mar 28 '18 at 07:02
  • That's the fourth time you have asked this question. I suggest if you haven't done so already that you backtrack a bit and 1) create a working select statement which 2) you convert to a working update statement and then 3) create an event knowing that the update works as intended. AND what do you mean by sent_date can be anything. Also sample data as text on the question would be useful. – P.Salmon Mar 28 '18 at 07:13
  • Couple more comments select datediff('2018-03-26','2018-04-01') = -6, Are your dates really stored as date fields? – P.Salmon Mar 28 '18 at 07:37
  • @Salmon...yes its running... – chetan kambli Mar 28 '18 at 09:59
  • @salmon...i used sent_date=DATE(CURDATE()-5),it is giving me the result.. – chetan kambli Mar 28 '18 at 10:00

1 Answers1

0

try CURDATE()-5

CREATE EVENT rot ON SCHEDULE EVERY 1 day DO 
    update barter_proposals 
       set proposal_status="Aborted"
     WHERE sent_date=DATE(CURDATE()-5)
       AND proposal_status = "Sent/Received"
Mohideen bin Mohammed
  • 18,813
  • 10
  • 112
  • 118