Support

Account

Home Forums General Issues Display day and month from date_picker field. Reply To: Display day and month from date_picker field.

  • Hi @kevin-mamaqi

    This isn’t really an ACF question. More of an general PHP question 🙂 But I’ll try and help you anyway.

    This code should do the trick:

    
    <!-- EVENTOS -->
    <div class="container">
    	<div class="row">
    	<div class="col-sm-12"><h2 class="seccion">Fotos</h2></div>
    	<?php
          $today = current_time('Ymd');
    
          $args = array(
            'post_type' => 'evento',
            'post_status' => 'publish',
            'posts_per_page' => '-1',
            'meta_query' => array(
              array(
                'key' => 'fecha_del_evento',
                'compare' => '>=',
                'value' => $today,
                )
              ),
            'meta_key' => 'fecha_del_evento',
            'orderby' => 'meta_value',
            'order' => 'ASC',
            );
    
          $query = new WP_Query($args);
          if ($query->have_posts()) :
            while ($query->have_posts()) : $query->the_post(); 
          ?>
          
    	      <div class="col-sm-3">
    	      	<?php
    		      	$datetime_string = get_field('fecha_del_evento');
    		      	$datetime = new DateTime($datetime_string);
    		      	$month = date_i18n('M', strtotime($datetime_string));
    		      	$day = $datetime_object->format("d");
    			?>
    			
    	      </div>
    
           <?php endwhile; ?>
      <?php wp_reset_postdata(); ?>
    
    <?php endif; ?>
    
    	</div><!-- #row -->
    </div><!-- #container -->