• Resolved paa1605

    (@paa1605)


    Hi folks

    Does anyone know how to change the format of the date in the post admin screen? Im not talking about how the date is shown on posts once live on a site as i know that can be changed under the settings tab. My question refers to how the date is shown in the backend post admin screen.

    I have added a custom column showing the revised date and it is currently in the following format:

    2012-03-13 11:39:46

    Anyone know how to change this?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • How did you add the custom column? Is there a call to the date() function in the code for that? If not, what code causes the date to display?

    Thread Starter paa1605

    (@paa1605)

    this is the code i have in my functions file

    // Register the column
    function revised_column_register( $columns ) {
        $columns['revised'] = 'Revised';
        return $columns;
    }
    
    add_filter( 'manage_edit-post_columns', 'revised_column_register' );
    
    // Display the column content
    function revised_column_display( $column_name, $id ) {
        if ('revised' == $column_name)
            echo get_post_field('post_modified', $id);
    }
    add_action( 'manage_posts_custom_column', 'revised_column_display', 10, 2 );
    
    // Register the column as sortable
    function revised_column_register_sortable( $columns ) {
    	$columns['revised'] = 'modified';
    
    	return $columns;
    }
    add_filter( 'manage_edit-post_sortable_columns', 'revised_column_register_sortable' );
    
    function revised_column_orderby( $vars ) {
    	if ( isset( $vars['orderby'] ) && 'revised' == $vars['orderby'] ) {
    		$vars = array_merge( $vars, array(
    			'orderby' => 'revised'
    		) );
    	}
    
    	return $vars;
    }
    add_filter( 'request', 'revised_column_orderby' );

    I got it from an article i found here

    Custom Sortable columns

    I can’t seem to see where the code is that controls the date format though. Thanks for taking the time to reply, much appreciated.

    I think you need to change this:

    echo get_post_field('post_modified', $id);

    to this:

    echo date('n/j/Y',strtotime(get_post_field('post_modified', $id)));

    You did not specify the format you wanted, so I set it to ‘n/j/Y’ to print the date like ‘3/6/2010’. Change that as desired. The link below has a table of the format codes:

    https://php.net/manual/en/function.date.php

    Thread Starter paa1605

    (@paa1605)

    Thanks vtxyzzy, worked perfectly!!!

    All the best!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to format the date in post admin??’ is closed to new replies.