I'm currently working with an MVC pattern and have at the same time fallen in love with the DateTime
class in PHP; I create a DateTime
object in the Model and form the date in the View with $date->format('Y-m-d')
.
My question is if there's any way to alter the MySQLi
object after a selection and change a MySQL timestamp column into an DateTime
object?
My current solution is to loop through the MySQLi
object and push every row to an array. It doesn't feel very sleek, though.
Any ideas?
If your reasoning is just to format the date, I think you could do something like this:
SELECT FROM_UNIXTIME(table.column, '%Y-%m-%d') FROM table
I looked it up from This Post.
Haven't tested it, but, it should work out better than extending the MySQLi class for a little thing like date formats.