Let’s say there’s a datetime column ($dateTimeCol) with the datetime value of “2010-02-16 00:00:00”, how would you get the date so that it can be formated as Feb 16, 2010?
This Won’t Work
<?php echo date("M j, Y", $datetimeCol); ?>
If you try the above, you will get the php error “A non well formed numeric value encountered…”
Here’s the right solution
<?php echo date("M j, Y", strtotime($datetimeCol)); ?>
The trick is to use strtotime to convert the datetime value ($datetimeCol) into a timestamp so that it can be manipulated by the php date() function.
Leave a Reply