Home › Forums › General Issues › Display day and month from date_picker field. › Reply To: Display day and month from date_picker field.
Hello @jonathan
Thanks, I did it and got this message:
Fatal error: Uncaught exception ‘Exception’ with message ‘DateTime::__construct():
Failed to parse time string (17/07/2015) at position 0 (1):
Unexpected character’ in /home/eurovia1/public_html/wildlion/wp-content/themes/wildlion/single-artista.php:207
Stack trace: #0 /home/eurovia1/public_html/wildlion/wp-content/themes/wildlion/single-artista.php(207): DateTime->__construct(’17/07/2015′)
#1 /home/eurovia1/public_html/wildlion/wp-includes/template-loader.php(74): include(‘/home/eurovia1/…’)
#2 /home/eurovia1/public_html/wildlion/wp-blog-header.php(16): require_once(‘/home/eurovia1/…’)
#3 /home/eurovia1/public_html/wildlion/index.php(17): require(‘/home/eurovia1/…’)
#4 {main} thrown in /home/eurovia1/public_html/wildlion/wp-content/themes/wildlion/single-artista.php on line 207
So I searched for a solution and came up with this code:
<?php
$datetime_string = get_field('fecha_del_evento');
$datetime = DateTime::createFromFormat('d/m/Y', '$datetime_string');
$month = date_i18n('M', strtotime($datetime));
$day = date_i18n('d', strtotime($datetime));
?>
<?php echo $day; ?>
<?php echo $month; ?>
The code returns the current day, while changing date_i18n to date returns 01-Jan. From here I’m a bit blocked.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.