Support

Account

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