I am currently working on a Wordpress project where I need to get some personalized message metadata, convert it to an DateTime instance and do the math with it.
When I echo get_post_meta, it looks like this.
2016.04.30 7:30
The format that I use to get an instance of DateTime is as follows.
Ymd A g: i
But the return value of DateTime::createFromFormat is false .
// 2016.04.30 PM 7:30 $start_at = DateTime::createFromFormat( 'Ymd A g:i', get_post_meta(get_the_ID(), 'as_date', true)); if ($start_at === false) { echo 'False format: ' . get_post_meta(get_the_ID(), 'as_date', true); } else { echo $start_at->getTimestamp(); }
Result False format: 2016.04.30 PM 7:30 .
What am I missing here? I think it should be something trivial, but I canβt get through.
source share