Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've created a custom profile field for my BP users and I'm looking to show the value on the user's profile page. The code below does this...

<?php bp_profile_field_data( array('user_id'=>get_the_author_meta( 'ID' ),'field'=>'birthday')); ?>

...But it displays it as "1985-10-30 00:00:00".

How can I format this to display like this: "October, 30 1985"

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I have no idea if BuddyPress has built in date functions but WordPress does and PHP does. This should do it:

$bpress_date = bp_profile_field_data( array('user_id'=>get_the_author_meta( 'ID' ),'field'=>'birthday'));
// $bpress_date = "1985-10-30 00:00:00"; // test
echo date('F, j, Y',strtotime($bpress_date));

PHP's date expects UNIXTIME. That is why the date string is passed through strtotime. It does not work without that step.

You probably want to consider using WordPress' date_i18n, however, which would look like:

echo date_i18n(get_option('date_format'),strtotime($bpress_date));

This gives you some ability to internationalize things as the date will displayed according to the blog's date format settings.

share|improve this answer
    
Awesome, thank you. This worked perfectly. –  Red Mar 24 '13 at 0:21
add comment

You would use the PHP function date() to format the birthday timestamp.

Example:

<?php 
$birthday = bp_profile_field_data( array('user_id'=>get_the_author_meta( 'ID' ),'field'=>'birthday'));
echo date('F, j Y', $birthday);
//would result in October, 30 1985
?>

http://www.php.net/manual/en/function.date.php

share|improve this answer
    
Thanks for the reply, this only seemed to want to return the date "Jan 1, 1970" –  Red Mar 24 '13 at 0:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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