I have a custom meta box, its just a straight-up text field, for an event date, formatted: YYYY/MM/DD ...I'd like to save that as a date stamp (so i can sort by event date), and display just the pretty date format on the design side (ie: 2011/09/24 becomes September, 24th, 2011).

I was using this tutorial as a guide: http://www.noeltock.com/web-design/wordpress/custom-post-types-events-pt1/

But I find its really hard to follow, and probably too complicated for what I'm doing.

So far I have this:

function event_date(){
global $post;
$custom = get_post_custom($post->ID);
$event_date = $custom["event_date"][0];

// - grab wp time format -
$date_format = get_option('date_format'); ?>

<label>Event Date (YYYY/MM/DD):</label>
<input name="event_date" value="<?php echo $event_date; ?>" />


Which works in spitting out: 2011/09/25. I've been trying to figure out what to do with that $date_format bit, any ideas what I'm missing to get 2011/09/25 display as September 25, 2011 on the front end?



You don't have to store it as a timestamp to order by date, yyyy/mm/dd will work just fine.

As for converting the format:

$date = '2011/09/19';
$date = strtotime( $date );
echo date( 'F j, Y', $date );

see php's strtotime and date

EDIT- oh, maybe I misunderstood, thought you said timestamp, not date. anyway, the conversion code in the second part is what you need. a unix timestamp is the number of seconds since January 1st, 1970.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.