date format of custom field
-
Hi there,
I found the solution for my question, but I don’t understand.
I have a custom field tweede_voorstelling. It’s a date/time field.I would like to change the format.
I refer to this field in my catlist-command like this:
[catlist name=”actueel” template=imgtit customfield_display=”tweede_voorstelling”]I do have a custom template: imgtit.
I added the two lines (see below). But then what?
I don’t understand:Now you can use the dateTime object to output your date wherever you want, in whatever format you want. Just call $dateTime->format(‘l jS F Y’)Here the answer of the author I found:
First create a custom template.
In the template file, use this code:
$date = get_post_meta( $post->ID, ‘[your custom field name]’, true );
$dateTime = DateTime::createFromFormat(“Y-m-d”, $date);Remember to replace [your custom field name] with an actual custom field name.
Now you can use the dateTime object to output your date wherever you want, in whatever format you want. Just call $dateTime->format(‘l jS F Y’);
Hope it helps.
- The topic ‘date format of custom field’ is closed to new replies.