Format mysql table date and show in Smarty

Asked

Viewed 106 times

0

I am developing a PHP page, using MVC structure and rendering tamplete files with Smarty.

However, it was difficult to get a date via Mysql (see format: YEAR-MONTH-DAY HOUR:MINUTE:SECOND

I would like it to be presented in the following form: DAY/MONTH/YEAR - TIME:MINUTE

I already managed to get the data in Mysql, as shown below:

    $feed = new feedAction();
    $feedPostsSelect = $feed->select();
    $view->assign("feedList",$feedPostsSelect);

    $view->assign("textFeed", "text");
    $view->assign("usuarioFeed", "idauthor");
    $view->assign("publishDateFeed", "publishDate");

And in the tpl file:

{$row.publishDate}

I’ve tried as in Smarty’s timestamp shows, that would be:

{$smarty.now|date_format:"%d/%m/%Y - %H:%M"}

But using $Row.publishDate|date_format does not work if you want to display some data on the screen.

How to proceed?

Thank you for your attention!

1 answer

1


Problem solved with success! In the query, where the data will be pulled from the database, it is necessary to get already formatted, that is, the query will be:

SELECT *, DATE_FORMAT(T1.publishDate, '%%d/%%m/%%Y - %%H:%%i') AS publishDateFormated FORM tabela;

Although no one has helped so far, I hope my own response will help someone! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.