Date formatting

Support MB Admin Columns Date formattingResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12315
    MemaddogMemaddog
    Participant

    Is it possible to format the date when using a datetime meta box in an admin column? By default, I'm getting the datetime formatted like this: "2018-12-15 18:00" which is readable, but not super user-friendly.

    #12356
    Anh TranAnh Tran
    Keymaster

    Hello, it's not possible yet. We're working on the date formats for Meta Box. When it's done, it will be shipped to the Admin Columns.

    #15545

    Found a solution for merging my date and time field to one. This could help you:
    functions.php

    
    add_action( 'admin_init', 'prefix_add_custom_columns', 20 );
    function prefix_add_custom_columns() {
        require_once get_stylesheet_directory() . '/my_theme/divi/Prefix_Custom_Admin_Columns.php';
        new Prefix_Custom_Admin_Columns( 'my_cpt', array() );
    }
    

    The Class:

    
    class Prefix_Custom_Admin_Columns extends MB_Admin_Columns_Post {
        public function columns( $columns ) {
            $columns  = parent::columns( $columns );
            $this->add( $columns, 'cpt_start', 'Start', 'before', 'date' );
            return $columns;
        }
        public function show( $column, $post_id ) {
            $value = rwmb_the_value( $column, '', $post_id, false );
    
            switch ( $column ) {
                case 'cpt_start':
                    $value = date( 'd.m.Y', strtotime( $value ) );
                    if( $value == '01.01.1970' ) {
                        echo '-/-';
                    } else {
                        echo $value;
                    }
                    $value = rwmb_the_value( 'cpt_start_time', '', $post_id, false  );
                    if( $value != '' && !is_null( $value ) ){
                        echo ' ( '.$value.' )';
                    }
                    break;
            }
        }
    }
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.