title: How to properly set "0000-00-00 00:00:00" as a DateTime in PHP
body: <p>I have a column <code>viewedAt</code> which is a <code>DATETIME</code> and accept <code>NULL</code> values. It's a software restriction to set that column on each new record as <code>0000-00-00 00:00:00</code> so I go through the easy way using Symfony and Doctrine as show below:</p>
  
  <pre><code>$entEmail = new Email();
  $entEmail-&gt;setViewedAt(new \DateTime('0000-00-00 00:00:00'));
  </code></pre>
  
  <p>But surprise PHP change that date to this <code>-0001-11-30 00:00:00</code> and SQL mode in MySQL server is set to STRICT so query fails. I have read a lof of topics here as <a href="https://stackoverflow.com/questions/10450644/how-do-you-explain-the-result-for-a-new-datetime0000-00-00-000000">this</a>, <a href="https://stackoverflow.com/questions/6592181/how-to-prevent-php-to-convert-a-datetime-object-with-0000-00-00-value-to-0001-1">this</a> and some other but didn't answer my doubt at all. I have made a few test with PHP alone and I got almost the same result:</p>
  
  <pre><code>$date = new DateTime("0000-00-00 00:00:00", new DateTimeZone('America/New_York'));
  echo $date-&gt;format('Y-m-d h:i:s');
  
  // outputs
  // -0001-11-30 12:00:00
  </code></pre>
  
  <p>Even with MySQL mode set to <code>STRICT</code> I did test the following query and it works as image below shows:</p>
  
  <pre><code>INSERT INTO emails(`emails_category`, `deliveredAt`, `viewedAt`, `data`, `createdAt`, `updatedAt`, `reps_id`, `targets_id`) VALUES ("sent","2015-10-29 06:08:25","0000-00-00 00:00:00",null,"2015-10-29 06:08:25","2015-10-29 06:08:25","005800000058eYcAAI","0018000001GO8omAAD")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/FTxeZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FTxeZ.png" alt="enter image description here"></a></p>
  
  <p>So <code>viewedAt</code> is accepting <code>0000-00-00 00:00:00</code> that value even if is not valid (I think it's kind of NULL or so)</p>
  
  <p>How I can fix this? Is there any work around? What did you suggest me on this specific case where this is a software requirement and can't be changed?</p>
  
  <p>I'm using Symfony 2.7.6, Doctrine 2.5.2 and PHP 5.5.30</p>