Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
MATHIEU LOISEAU

Date column: unable to use custom format

Hello,

I added to my user table a “last_login” column.

Updated using: update_user_meta($user->ID, 'first_login', \Carbon\Carbon::now()->format('d/m/Y H:i:s'));
Also tried with: update_user_meta($user->ID, 'first_login', \Carbon\Carbon::now()->timestamp);

I then used as date format “d/m/Y H:i:s” and “u”: nothing is displayed in column. I have to remove the “date” format to have the raw text value displayed.

Thanks

3 years, 7 months ago
MATHIEU LOISEAU

Edit: my example use “first_login”, but my tests are with “last_login”, and from database user_meta table, values are OK and match the defined format.

3 years, 7 months ago
Stefan van den Dungen Gronovius
Developer

So just to be sure.
You’ve used our custom field column with type set to ‘Date’?
When the actual value is of the meta field is a timestamp, I expect the display value should work without any problem. But when your value is stored as ‘d/m/Y H:i:s’ I suspect it will not work as intended.
The best format for in the database in my opinion is a timestamp or ‘Y-m-d H:i:s’ format. Both formats can also be used natively to sort and filter in the database, so not only for Admin Columns but probably other features as well, I recommend to use one of those.

But if the timestamp is not working as expected, I’m curious why it doesn’t work. Can you contact me at support@admincolumns.com and send me a screenshot of your column settings for this specific column you’ve setup?

3 years, 7 months ago
Tobias Schutter
Developer

The issue here was that the date value was a unix timestamp. Admin Columns Pro uses the ‘yyyy-mm-dd hh:ii:ss’ format as its default. To change it to unix timestamp use this code snippet:

function acp_set_custom_field_stored_date_format( $date_format, ACP\Column\CustomField $column ) {

	if ( 'my_date_meta_key' === $column->get_meta_key() ) {

		// Set the date format to 'U' Unix timestamp
		$date_format = 'U';
	}

	return $date_format;
}

add_filter( 'acp/custom_field/stored_date_format', 'acp_set_custom_field_stored_date_format', 10, 2 );
1 year, 10 months ago

You must be logged in to reply to this topic.