0

I want to format the created_at field date from the original to something like 15h33 12/01/2012 to be shown in the indexSuccess.php.

Could you help me?

Charles
  • 50,943
  • 13
  • 104
  • 142
user1079624
  • 3
  • 1
  • 3
  • Similar question: [Format date in the indexSuccess.php](http://stackoverflow.com/questions/7203559/format-date-in-the-indexsuccess-php), [How to format dates based on locale?](http://stackoverflow.com/questions/3924891/how-to-format-dates-based-on-locale),[How to format a getUpdatedAt() kind of date in Symfony?](http://stackoverflow.com/questions/2141252/how-to-format-a-getupdatedat-kind-of-date-in-symfony) – denys281 Jan 31 '12 at 09:10

3 Answers3

3

You can also use the Date helper like this in your view :

<?php use_helper('Date'); ?>
<?php echo format_date($comment->getCreatedAt(), 'dd-MM-yyyy, HH:mm'); ?>
Yvan L.
  • 162
  • 4
  • 15
  • This would work as well, but if you wanted the same format across templates, you would have to make this call several times. In my example you need only format the date once. – Mike Purcell Jul 03 '13 at 19:27
  • Only a small point but doesn't it violate MVC a little to do that in the action? Would have thought date formatting belonged in the view? – Tofuwarrior Feb 26 '14 at 14:09
1

In your actions script you want to do something like:

$createdAt = strtotime($dbResults['created_at']);

$this->createdAt = date('H\hi m/d/Y', $createdAt);

Then just reference the available createdAt in your template:

<div>Created at: <?php echo $createdAt?></div>

More date formatting options can be found at the PHP date Api docs.

Mike Purcell
  • 19,847
  • 10
  • 52
  • 89
0

If you are using Propel rather then Doctrine then you can do this kind of thing:

$model->getCreatedAt('Y-m-d H:i:s');

Which is fabulously simple! Sadly Doctrine 1.2 doesn't implement this. I haven't used Doctrine2 so not sure whether you can do it with that.

Tofuwarrior
  • 669
  • 9
  • 21