The date/time related field types for CMB2 store all their values as Unix timestamps in the database with the exception of text_datetime_timestamp_timezone
which stores it’s value as a serialized DateTime object.
- text_date_timestamp Date Picker (UNIX timestamp)
- text_datetime_timestamp Text Date/Time Picker Combo (UNIX timestamp)
- text_datetime_timestamp_timezone Text Date/Time Picker/Time zone Combo (serialized DateTime object)
See: https://github.com/WebDevStudios/CMB2/wiki/Field-Types
What you see in the metabox is a conversion from the Unix timestamp to a human readable format which I believe you can adjust to your liking using the date_format
key when calling $cmb->add_field()
.
In your case, all you need to do is pass your timestamp through PHP’s date()
function to format the result as you desire.
Example:
$text = get_post_meta( get_the_ID(), '_cmb2_event_date_prefix_datetime_timestamp', true )
echo date('Y-m-d H:i:s A', $text ); // results in 2016-03-07 08:40:00 AM
See the documentation on PHP’s date()
function for formatting instructions: