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?

1

3 Answers 3

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'); ?>
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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?
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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.