I want to chage date format to d-m-y means day-month-year format . I have added

'date_format' => __( 'd-m-Y', 'cmb2' )

But not working. now it's month-day-year formated . Actually i want to change date format like month-day-year to day-month-year.

mata field

Here is code:

add_filter( 'cmb_meta_boxes', 'cmb_sample_metaboxes' );
function cmb_sample_metaboxes( array $meta_boxes ) {

    $prefix = '_single_';

    $meta_boxes[] = array(
        'id'         => 'coupons_metabox',
        'title'      => 'Coupon details',
        'pages'      => array( 'coupons', ), // Post type
        'context'    => 'normal',
        'priority'   => 'high',
        'show_names' => true, // Show field names on the left
        'fields' => array(
            array( // Text Input
                'name' => 'The date the coupon expires', // <label>
                'desc'  => 'The expiration date of the coupon. Leave if empty if the coupon doesn\'t have an expiration date.', // description
                'id'    => $prefix . 'date', // field id and name
                'type'  => 'text_date_timestamp', // type of field,

    // Add other metaboxes as needed

    return $meta_boxes;

add_action( 'init', 'cmb_initialize_cmb_meta_boxes', 9999 );
 * Initialize the metabox class.
function cmb_initialize_cmb_meta_boxes() {

    if ( ! class_exists( 'cmb_Meta_Box' ) )
        require_once 'init.php';

  • The right place to ask this question is the cmb forums – Mark Kaplun Mar 14 '15 at 7:44
  • 1
    Please be very clear what you want. This update renders my answer useless. Please be sure you add all info before you post a question so that no one wastes their time answering irrelevant info – Pieter Goosen Mar 14 '15 at 14:53
  • Sorry for that . Actually i want to change date format like month-day-year to day-month-year. – Saiful Mar 14 '15 at 15:01
  • That is info that should be in your question, and not in a comment where nobody actually sees it – Pieter Goosen Mar 14 '15 at 15:21


You should be using date_create_from_format or its alias DateTime::createFromFormat() to convert on format to another. You can try the following

$date = DateTime::createFromFormat('m-d-Y', '03-09-2015');
echo $date->format('d-m-Y');

This will convert 03-09-2015 to 09-03-2015


This is more a PHP question than Wordpress question. You can simply use str_replace to change the / in your date to -. You are not changing the format, so no need for date_format or any other date related functions

You can try something like

$date = '03/09/2015';
$modified_date = str_replace( '/', '-', $date );
echo $modified_date;

This will output 03-09-2015

| improve this answer | |
  • See my update. Please read How to Ask and visit help center and take a tour to learn how the SE sites work, and how to ask a good question and also see what is on topic and what is not. – Pieter Goosen Mar 14 '15 at 16:24
  • Sorry. How to add this function in wordpress custom meta field ? – Saiful Mar 15 '15 at 13:05

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