Support

Account

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.