Support

Account

Home Forums General Issues Date Picker Less than 30 days Reply To: Date Picker Less than 30 days

  • Hi @garywright

    I think I’ve made a mistake in my reply there. It should be like this:

    // Get the raw date and convert it to timestamp
    $date_timestanp = strtotime(get_field('acf_date_field_name', false, false));
    
    if ($date_timestanp < strtotime('-30 days')) { 
        echo "30 days";
    } else {
        echo "Its OK";
    }

    If you use ACF PRO version, the format doesn’t matter as long as you set the format to false in the get_field() function.

    In the other hand, if you use the free version, you need to use the right format before converting it to a timestamp. It should be something like this:

    // Get the raw date and convert it to timestamp
    $the_date = get_field('acf_date_field_name', false, false);
    $the_date = str_replace('/', '-', $the_date);
    $date_timestanp = strtotime($the_date);
    
    if ($date_timestanp < strtotime('-30 days')) { 
        echo "30 days";
    } else {
        echo "Its OK";
    }

    If that doesn’t work, could you please debug the data like this:

    echo $the_date;
    echo "<br />";
    echo $date_timestanp;

    Thanks 🙂