3 Replies - 1099 Views - Last Post: 23 April 2012 - 04:37 AM

#1 byrandomby1  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 124
  • Joined: 08-March 11

trigger on date change

Posted 22 April 2012 - 09:52 AM

how do i update a derived 'age' attribute if triggers do not support date changed event?
Is This A Good Question/Topic? 0
  • +

Replies To: trigger on date change

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: trigger on date change

Posted 22 April 2012 - 10:26 AM

I've never heard of anything like a "date changed event" in MySQL. Could you elaborate?
Was This Post Helpful? 0
  • +
  • -

#3 byrandomby1  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 124
  • Joined: 08-March 11

Re: trigger on date change

Posted 22 April 2012 - 05:30 PM

I have a "Person" table, with DateOfBirth and Age attributes.
I want the Age attribute to automatically update when the server date changes, so that the correct age of the person will be displayed.
Was This Post Helpful? 0
  • +
  • -

#4 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 799
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: trigger on date change

Posted 23 April 2012 - 04:37 AM

I can see where you're coming from, but I doubt you need triggers. If you want the output to reflect a change in age, you can achieve this via PHP code easy enough. If you're looking at WHERE clauses in a query, then you can do this via the DATEDIFF() function in MySQL. If your dates are stored in unixtime, then simply multiply seconds * minutes * hours * days, etc, to get the difference between the integers.

Age is a derivative of the timedate value someone was born and "now". It's not necessary to store age as a value, it can be derived.

This post has been edited by e_i_pi: 23 April 2012 - 04:39 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1