Two days ago I opened a thread related to the command 'timestampdiff()' -> Old thread). I think I've described the problem a litte bit too complicated, so I will describe it easier in this new thread :-)
Is it possible, to replace the two date values from the command TIMESTAMPDIFF(YEAR, '1935-03-15', '2010-06-01') automatically with custom fields, which I'm using in the wordpress-table wp_postmeta?
On my OLD website, which serves data of thousands of persons, I was working directly with a custom mysql-table 'persons', which included among others two fields 'birthdate' and 'deathdate'. To get all ages of all persons of the database in a list, I was using this command:
SELECT DISTINCT TIMESTAMPDIFF(YEAR, birthdate, deathdate) AS age_year FROM persons
This command worked perfectly, and using a while-loop I got automatically a table of contents with each age of the persons in my database.
Now I'm about to relaunch my website, and from now I would like to use $wpdb to retrieve the data. I don't use the custom table 'persons' anymore, and all data of the persons are stored now as custom fields in the wp_postmeta-table. That means, I can't address the fields 'birthdate' and 'deathdate' so easy as before. I got only one field meta_key and one field meta_value in the table.
How can I use these two custom fields from wp_postmeta within TIMESTAMPDIFF in the SELECT-command and convert them in an ALIAS as before? How should I change the old code, when using $wpdb? I would be happy, if anyone could help me :-)
Thank you very much in advance! Andreas