Difference between Mysql date and PHP data?

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


7 points

I often get confused on mysql and php date time. Can anybody help me with easy to remember pointers?



-5 points

Following code would help you understand the difference between mysql time and php time or date.

<?php     
// $mysqldate is ready to be inserted into a DB
// $phpdate is ready to used in a PHP script

 // For use with DATESTAMP type or TIMESTAMP type
  
$mysqldate date'Y-m-d H:i:s'$phpdate );
 
$phpdate strtotime$mysqldate );

   
// For use with DATE type
 
$mysqldate date'Y-m-d'$phpdate ); // H:i:s will be 00:00:00
   
$phpdate strtotime$mysqldate );
?>

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.