datezend-date

convert date to a different format


I have a date of the form mm-dd-yyyy. I need to convert into YYYY-MM-dd to store in the database. I did the following

$eff_date=$this->post['effective_date'];
$eff_date=$eff_date->toString('YYYY-MM-dd');

I get the following error:

Call to a member function toString() on a non-object

I am not sure how to fix it.


Solution

  • $eff_date is a Zend_Date object? or just a string? if it's just a string you will need to instance the Zend_Date object first:

    <?php
    $eff_date = new Zend_Date($this->post['effective_date'], 'mm-dd-yyyy', 'en');
    $eff_date = $eff_date->get('YYYY-MM-dd');