Display Custom Date / Time Format on the Front End

Support General Display Custom Date / Time Format on the Front EndResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #34376
    Brent WilsonBrent Wilson
    Participant

    I have a custom field date/time picker. But on the front end, I want to display data from that field in a custom format (like time as 7:30 PM, date as July 23, 2020). How can I do this in the Block editor? Is there a special format of short code I can use?

    #34404
    Long NguyenLong Nguyen
    Moderator

    Hi Brent,

    If you want to display the date time on the frontend in different formats, you can set the setting timestamp of the field to true. Please read more on the documentation https://docs.metabox.io/fields/datetime/#template-usage

    #34411
    Brent WilsonBrent Wilson
    Participant

    So, can you explain more about how to do this to a coding beginner? How can I display data from the date/time field in two different places in a template built with the block editor?

    In one place, I want to display as l, F j

    In another place, I want to display as g:i A

    #34433
    Long NguyenLong Nguyen
    Moderator

    Hi Brent,

    If you build your template with coding, you can add this code to the template file

    $value = rwmb_meta( $field_id );
    echo date( 'F j, Y @H:i', $value );
    

    If you build your template by using prebuilt blocks (just drag and drop), you can use the helper shortcode to show the time value

    [rwmb_meta id="datetime" format="F j, Y @H:i"]

    Remember to set the timestamp to true. Refer to the documentation
    https://docs.metabox.io/shortcode/
    https://docs.metabox.io/fields/datetime/#template-usage

    #34467
    Brent WilsonBrent Wilson
    Participant

    Specifying the format in the shortcode worked for me! Thanks for your help on this!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.