Get the stored date in symfony2 doctrine mongodb

577 views Asked by At

I have created a console command page in my bundle for cronjob. Here is the code

class MyCommand extends Command {

protected function configure()
{
    $this
        ->setName('cron:item_email')
        ->setDescription('product notification for customer that reserved');
}

protected function execute(InputInterface $input, OutputInterface $output)
{

    $this->container = $this->getApplication()->getKernel()->getContainer();
    $em = $this->container->get('doctrine.odm.mongodb.document_manager');
    $wishlist = $em->getRepository('xxxxBundle:Wishlist')->findAll();
    foreach($wishlist as $wish){
        if($wish->getReservedDate()){
      //  $output->writeln($wish->getId());
        $output->writeln($wish->getReservedDate());
    }

    }

}

}

Here I am retrieving mongo db date "$wish->getReservedDate()" But I am getting the output like this

2013-07-03 13:46:42
3
Europe/Berlin

How I get the date only for ex: 2013-07-03 13:46:42

1

There are 1 answers

0
kratos On BEST ANSWER

$wish->getReservedDate()->format('d/m/Y H:i:s')

Also as a side note, the ID has the date stored in it also.

Just a FYI