Support Forum
Support › MB Admin Columns › Admin Column - Date FormatResolved
Hey,
currently I save the format of my datapicker as 'Y-m-d' (bc of filtering) and jsoptions as 'dd.mm.yy'.
However, the problem is that in the admin columns 'Y-m-d' is used. I know that is because it is stored that way in the database but in my opinion is very impractical.
Would there be the possibility to implement something like:
admin_columns' => [
'dateFormat' => 'dd.mm.yy',
],
Or is there a way I haven't seen yet to take the jsoptions as admin column format?
Hi,
Please refer to this tutorial to change the display another date format https://docs.metabox.io/using-two-date-formats/
Let me know how it goes.
Hey Long, thanks for your fast reply!
But that doesn't change my initial problem!
My Date Value as saved as Y-m-d in the Database.
The display for the date is saved as d.m.Y.
In the Admin Columns the Date is shown as Y-m-d (Database Format).
But i want to display the date in the admin columns as the display date (d.m.Y)! Without changing the database formatting.
I guess this isn't possible?
See additional screenshots:
Admin Columns Format:
https://ibb.co/Xtjg8x8
Display Format:
https://ibb.co/0mVKNwN
Wanted Result (without changing the database format):
https://ibb.co/f4Cg3Mj
Hi,
The admin column uses the helper function rwmb_the_value
to show the field value. You can use this filter hook to change the date format when showing on the backend. For example:
add_filter( 'rwmb_the_value', function( $output, $field, $args, $object_id ) {
$value = rwmb_meta( 'date_picker', $args, $object_id );
if( is_admin() ) {
$output = date( 'd F, Y', strtotime( $value ) );
}
return $output;
}, 11, 4 );
Admin column: https://share.getcloudapp.com/kpu6kg7g
Database: https://share.getcloudapp.com/BluDg9Y7
Read more on the documentation https://docs.metabox.io/filters/#rwmb_the_value
Absolutely wonderful! Thank you very much for your awesome support, again and again!
Another Problem has occurred, now every admin column is taken from this specific field 😀
See screenshot: https://ibb.co/wyWwYpX
Hi,
If you have more admin columns for other fields, you can add the condition to show for a specific field as well.
add_filter( 'rwmb_the_value', function( $output, $field, $args, $object_id ) {
$value = rwmb_meta( 'date_picker', $args, $object_id );
if( is_admin() && $field['id'] == 'date_picker') {
$output = date( 'd F, Y', strtotime( $value ) );
}
return $output;
}, 11, 4 );
Get the field settings from the variable $fields
https://docs.metabox.io/field-settings/#general
And again, thank you very much. Makes sense! You and the whole meta box team are wonderful