1. PROMO Subscribe our All Access Pass @ 75% OFF & access all our 16+ premium Divi extensions: Divi Block Pro, Carousel Toolkit, etc.LEARN MORE
Dismiss Notice
NEW Divi.Help Pro Carousel AI Toolkit - Magically turn your Divi design into carousel, simply by using our online toolkit. No plugins needed. Now it works with Divi 5 as well!Try our carousel AI toolkit
BEST Divi Block - A revolutionary drag & drop tool to easily mix & match 960+ premade blocks (Light & Dark) to kick start your Divi site design. Special module designs are included as well. Also newly added AI generator & color. Now it works with Divi 5 as well!
Learn More About Divi BlockFree Version ~ 340+ Free Blocks

Show age in year

Discussion in 'Free Divi Community Forum' started by sanjavi, Jun 27, 2022.

  1. sanjavi

    sanjavi New Member

    hello, I'm working with divi and I have this code in the template
    "echo do_shortcode('[et_pb_section global_module="4084"][/et_pb_section]');"

    the problem I have is that it is a group of acf fields and I have a data Picker and it gives me the date of birth when what I am looking for is that it gives me the age

    I have seen code like this:

    "function get_age_by_date($date_of_birth)
    {
    $birth = new DateTime($date_birth);
    $now = new DateTime(date("Y-m-d"));
    $difference = $now->diff($birth);
    return $difference->format("%y");
    }
    // Try
    $dates = ['2020-05-05', '1990-01-01', '1999-01-01', '2002-12-31'];
    foreach($dates as $date){
    printf("Age for %s: %d\n", $date, get_age_according to_date($date));
    }"

    but i have no idea if i can implement this, thanks in advance
     
    1. PRO MEMBER PERKS Divi Block Pro - Premade floating button design for your Divi site without using any plugins:View Demo
  2. Divi.Help

    Divi.Help Administrator
    Staff Member

    It would be something to do with ACF then.

    I found this: https://support.advancedcustomfields.com/forums/topic/calculate-age-from-date-field/

    They share the PHP code to output the age with date picker. But I doubt that you create your page with PHP coding.

    So I guess you may create a custom shortcode at child theme functions.php file for that & output on your page (not sure if that will work or not).

    This is a sample shortcode:
    Code:
    Log In or Sign Up to view this code.
    And you may display the shortcode by placing this at a text module: [ageyear]