Jklyn Jklyn - 1 year ago 102
PHP Question

How to get only day and month of a date from custom field of wordpress?

I'm trying to get only day and month of custom field date of wordpress. I've managed to get both but I need to display month and date in different variables.Like: 27JUL. Here is my code.

<?php
$time = strtotime( get_field( 'date' ) );
$date = date( 'M d', $time );
echo "$date";
?>

Answer Source

Here's your code:

<?php
   $time = strtotime( get_field( 'date' ) );
   echo '<span class="day">' . date( 'd', $time ) . '</span><span class="month">' . date( 'M', $time ) . '</span>';
 ?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download