title: Converting data format with PHP from XML
body: <p>In the XML file, the date format is being received as: 20140327163000 (YYYYMMDDHHMINSEC). I need to parse the date and convert it into the following format (DD/MM/YYYY HH:MIN:SS) before posting it into the database. The following is the code I am using, however it is not posting anything in the database:</p>
  
  <pre><code>&lt;?php 
  
  // Create connection
  $con=mysqli_connect("localhost","test","test","epg");
  
  // Check connection
  if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
  
  $dir = "xml-files/";
  if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
      while (($file = readdir($dh)) !== false) {
        if (($file !== '.') &amp;&amp; ($file !== '..') ) {
      $doc = simplexml_load_file($dir . $file); 
  
  foreach ( $doc-&gt;ScheduleData-&gt;ChannelPeriod as $channelPeriod )
  {
     $channelId = $channelPeriod-&gt;ChannelId;
  
     foreach ( $channelPeriod-&gt;Event as $event )
     {
        $beginTime = $event['beginTime'];
        $duration = $event['duration'];
        $programName = $event-&gt;EpgProduction-&gt;EpgText-&gt;Name;
        $description = $event-&gt;EpgProduction-&gt;EpgText-&gt;Description;
        $EventId = $event-&gt;EventId;
  
           $format = 'd-m-Y H:i:s';
          $date = DateTime::createFromFormat($format, '$beginTime');
  
        $sql = "insert into `epg` (`EventId`,`ChannelId`, `BeginTime`,`Duration`, `ShortName`, `Description`) values ('$EventId','$channelId', '$date','$duration', '$programName', '$description')";
  
          if (mysqli_query($con,$sql))
        {
        echo "Database updated successfully&lt;br /&gt;";
        }
      else
        {
        echo "Error creating database: " . mysqli_error($con)."&lt;br /&gt;";
        }
  
  
                      }
                  }
              }
          }
    closedir($dh);
      }
  }
  
  $sql_delete = "DELETE FROM `EPG` WHERE BeginTime &lt; ";
  
  function deleteFiles($dir) {
      $files = glob($dir);
      foreach($files as $file){ 
        if(is_file($file))
          unlink($file); 
      }
  }
  
  deleteFiles("xml-files/*");
  
  ?&gt;
  </code></pre>