1

I'm trying to save data using ZF2 Doctrine ORM Module using dynamic paramter as entity class name and initializing its object and saving data using dynamic values from excel sheet header,

$time = \PHPExcel_Style_NumberFormat::toFormattedString($rowData[0][$key], 'hh:mm:ss');
$obj->$setter(\DateInterval::createFromDateString($this->secondsToTime(strtotime($time))));
$this->orm->persist($obj);
$this->orm->flush();

$this->secondsToTime(strtotime($time)) is returning time in format 4 hours 5 minutes 6 seconds

Field type is time, when I print $obj->getter(), it prints:

DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 4
    [i] => 5
    [s] => 6
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

But it doesn't save its value as 4:05:06 in database, it saves 00:00:00. I tried answer from here

Community
  • 1
  • 1
Vipul
  • 655
  • 2
  • 6
  • 22
  • 1
    What's type is the column? I think you should use a \Datetime php object instead of DateInterval and map him as a [doctrine time field type](http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#time). Hope this help – Matteo Mar 24 '15 at 13:10
  • 1
    its crazy, I used it before but there were errors, and now its working, i might have missed something – Vipul Mar 27 '15 at 09:32
  • so you don't change your code?Now correctly save on db? What is the column type of the field? – Matteo Mar 27 '15 at 09:33
  • @Matteo I mean I tried Datetime() earlier, but there was error and now I tried it again and its working perfectly. I might have missed something there and it made be believe that DateTime will not work and thats why I was trying something else, field type is time – Vipul Mar 27 '15 at 09:44

0 Answers0