Home › Forums › Backend Issues (wp-admin) › SQL command to update the age field based on date of birth › Reply To: SQL command to update the age field based on date of birth
May I answer my question..this solve my problem and it’s possible to achieved this through sql command query like the one below…I execute this 2 command on phpmyadmin
or thru plugin used this – SQL Executioner, not updated for a long time but still working till now..I don’t have any problem with..
UPDATE wp5m_usermeta AS m1
JOIN wp5m_usermeta AS m2 ON m1.user_id = m2.user_id
SET m1.meta_value = DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), m2.meta_value)), '%Y') + 0
WHERE m1.meta_key = 'mag_age'
AND m2.meta_key = 'mag_date_of_birth'
or this one also works
UPDATE wp5m_usermeta AS m1
JOIN wp5m_usermeta AS m2 ON m1.user_id = m2.user_id
SET m1.meta_value = TIMESTAMPDIFF(YEAR, m2.meta_value, CURRENT_DATE)
WHERE m1.meta_key = 'mag_age'
AND m2.meta_key = 'mag_date_of_birth'
You can use STR_TO_DATE() to parse dates in other formats. STR_TO_DATE(m2.meta_value, ‘%Y%m%d’
Thank you sir John Huebner
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.