I retrieve the date of an actor by selecting the date. 'data_nasterii' is the name of the custom field.

<?php $data = get_field('data_nasterii'); echo date("d/m/Y", strtotime($data)); ?>

If i do not select anyting, I'd like to return: N/A for the actor birthday.
How can I integrate in this code?

If there's a value:
Ex: Birthday :22/11/1978

If I don't select anything I want:
Birthday: N/A


I'm not certain what an empty get_field returns, as it's from a plugin.

However, assuming it provides FALSE or an empty string:

$data = get_field( 'data_nasterii' );
echo ( $data ? date( "d/m/Y", strtotime( $data ) ) : 'N/A' );
  • 1
    No problem. Please click the tick next to my answer so other people know it works. – vancoder Apr 9 '13 at 22:39

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.