Matthew Vaccaro

Guns, God, Country, and Code
  • Index
  • Blog
  • Snippets
  • Switch WP Date Number to Month

    While working with custom post types and some event/date related stuff, I came upon an issue of how to easily transform the numbered output of the jQuery date picker I was using for users to choose dates inside a custom post type, into the abbreviated month names such as Jan. and Feb. (As opposed to 01 and 02).

    EDIT: This was more complex, but I neutered it down to fit this specific example.

    <?php
    
    $date = 01-08-2011;
    list($year, $month, $day) = explode("-", $date);
    
    switch ($month) {
    case "01":
    	echo "JAN";
    	break;
    case "02":
    	echo "FEB";
    	break;
    case "03":
    	echo "MAR";
    	break;
    case "04":
    	echo "APR";
    	break;
    case "05":
    	echo "MAY";
    	break;
    case "06":
    	echo "JUN";
    	break;
    case "07":
    	echo "JUL";
    	break;
    case "08":
    	echo "AUG";
    	break;
    case "09":
    	echo "SEPT";
    	break;
    case "10":
    	echo "OCT";
    	break;
    case "11":
    	echo "NOV";
    	break;
    case "12":
    	echo "DEC";
    break;
    }
    echo '<span class="eventDay">'; echo $day; echo '</span>';							
    
    ?>
    Go Back