CMB2 icon indicating copy to clipboard operation
CMB2 copied to clipboard

Date picker doesn't show correctly when I set date format

Open ancilkanto opened this issue 8 years ago • 5 comments

Date picker doesn't show correctly when I set date format. When I set the date format to d/m/Y, I'm unable to choose a date after today, the field goes blank.

ancilkanto avatar Dec 14 '17 06:12 ancilkanto

Can you please provide your CMB2 configuration?

tw2113 avatar Dec 14 '17 16:12 tw2113

$tenders_meta->add_field( array(
		'name' => esc_html__( 'Closing Date', 'notion' ),
		'desc' => esc_html__( 'Specify the closing date.', 'notion' ),
		'id'   => $prefix . 'tender_closing_date',
		'type' => 'text_date',
		'date_format' => 'd/m/Y',
		
	) );

ancilkanto avatar Dec 15 '17 05:12 ancilkanto

That 'date_format' cannot be parsed by php's strtotime(). See this answer on stackoverflow: https://stackoverflow.com/a/2891949

Basically, you can use either 'm/d/Y' or 'd-m-Y', but not 'd/m/Y'. If you do want to keep this format, you'll have to do some re-converting magic with the 'sanitization_cb' parameter.

jtsternberg avatar Dec 15 '17 14:12 jtsternberg

@ancilkanto Just use text_date_timestamp and when you need to output it use date_i18n

stuartshields avatar Dec 19 '17 04:12 stuartshields

I had the same issue for months and new found, maybe add an error in CMB?

Mte90 avatar Jul 15 '19 14:07 Mte90