-2

How can I decrement a MySQL field every day?

Such as:

field1= 30 and after 24hours -> field1=29 until 0.

halfer
  • 19,824
  • 17
  • 99
  • 186
ERC20
  • 61
  • 1
  • 1
  • 3
  • 5
    What do you actually need this for? I have a feeling you'd be much better off just calculating the value when you need it, without needing to decrement it in "realtime". – deceze Aug 23 '12 at 15:05
  • What is the purpose of this functionality? Something tells me that your solution to a problem is more complicated than it needs to be. – Matt Aug 23 '12 at 15:06

2 Answers2

2

You'd probably be better off placing the current date in the database, and then use DATEDIFF to get the days since. You could even do 30 - DATEDIFF and then have the number the way you want it.

h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
1

You can execute a Unix cron job (there's some informations here) which will execute your PHP script every day.

Community
  • 1
  • 1
Julien Fouilhé
  • 2,583
  • 3
  • 30
  • 56