How to customize date display?

Dear experts,

I want to display my date (unixtime in database) to display in a specified format (e.g: 12-10-2013) and saving back using unixtime again.

ProductPurchaseForm.php

class ProductPurchaseForm extends Form
{
    $publish_time = new Text('publish_time', array('class'=>'form-control input-lg'));
    $this->add($publish_time);
}

edit.html

<form id="product-purchase-update-form" class="form-horizontal" method="post" role="form">
    {{ form.render("publish_time") }}
</form>

ProductPurchaseController.php

public function saveAction()
{
    if ($this->request->isPost())
    {
        ProductPurchase::save();
    }
}

Where should I put the date filter for displaying with a specified format?

Thank you so much

Jim



85.4k

How are you setting the value in the element? Is the value got from $_POST?

@Phalcon

Yes. I got the value from $_POST

Any ideas?



7.3k

Idea is very simple :) When you receive your POST publish_time, you can use strtotime in any variants: or when you binding POST data to model in controller, or when you save your data to table in model (beforeSave) just is easy :)