Home › Forums › General Issues › Extract year and Month from date picker custom field › Reply To: Extract year and Month from date picker custom field
In addition to Elliot’s suggested method, if you didn’t want to change the value saved to the database, you could use the DateTime ‘format’ method:
$date = get_field("my_date_field");
// assuming your return format is "Ymd"
$dateTime = DateTime::createFromFormat("Ymd", $date);
if ( is_object($dateTime) ) {
$month = $dateTime->format('F');
$year = $dateTime->format('Y');
//...
}
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.