Tell us what you are trying to do? get the year of a birth date and calculate current age base on today date
Is there any documentation that you are following? https://toolset.com/documentation/customizing-sites-using-php/functions/#date
Is there a similar example that we can see? https://toolset.com/forums/topic/calculate-age-from-date-of-birth-custom-filed/
What is the link to your site?
hidden link
I'm trying to get the birth date first using the code:
$user_id = THE USER ID COMES HERE;
echo (types_render_usermeta('wpcf-birth-date', array('user_id' =>$user_id , "style" => "calendar")));
I get nothing.
my scenario is as follow
user insert BD on his profile (user custom field)
I pull the user birth date year in the format YYYY i.e. 1989
than get today date
and calculate the age into a custom field
Please advise,
thanks,
David
Dear David,
I assume the custom field "wpcf-birth-date" is a custom date field created with Types plugin, when you use function types_render_field(), you do not need to set the "wpcf-" in the field slug, for example, you can try this:
$user_id = THE USER ID COMES HERE;
$birthdate = types_render_usermeta('wpcf-birth-date', array('user_id' =>$user_id , "output" => "raw")); // the custom field value
$age = floor((time() - $birthdate)/(365*24*60*60));
Thanks Luo,
yes, the "wpcf-birth-date" is a custom date field created with Types
your code still had the "wpcf" in it and it gave me some issue but once I removed it, it works 🙂
Thanks,
for the quick help.
David