0

NET. I want to modify a field "Age" for all account holders in my MYSQL database once an year. Is there any way to automate this task?

Deepak Joy Jose
  • 103
  • 1
  • 3
  • 14

2 Answers2

4

I know this doesn't directly answer your question, but if you want to update Age every year, would it not make more sense to record their DateOfBirth and then calculate their age from that?

However, to answer your question, you could look at using the TaskScheduler class.

Community
  • 1
  • 1
Richard
  • 8,110
  • 3
  • 36
  • 59
0

You can use the event scheduler to achieve the above purpose in Mysql. No need to write down the code in frontend, do the job in backend.

To create an event, you can use the create event statement. Here is an explanation with example.

Something like this:

CREATE EVENT CalculateAge_Event
     ON SCHEDULE EVERY 1 YEAR
     DO 
Update myschema.Employee Set Age = DATEDIFF(NOW(),DateOfBirth);
Romil Kumar Jain
  • 20,239
  • 9
  • 63
  • 92