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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.