0

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.

newbie
  • 1,023
  • 20
  • 46

1 Answers1

1

$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');
Mario César
  • 3,699
  • 2
  • 27
  • 42
  • thanks @mario ..now if i retrieve it from the database to display. Do i reconvert it into mm/dd/yyy in the same way? – newbie Feb 22 '12 at 03:08
  • Reconvert to store in the DB? yes, definitively. I recommend you if you're using Zend, you may look into using Zend_DB to use models, this way it will be more transparent, you now like just giving the Zend_Date object and it will convert it to the proper DB Date String. – Mario César Feb 22 '12 at 03:14
  • Use Zend_Filter to normalize it before you store it into the database. – Liyali Feb 22 '12 at 04:05