Format PHP Date to MySQL Format


When you insert or update a date in a mysql Table you have to remember that Mysql have 3 types of date

  • DATETIME         ( default format 0000-00-00 00:00:00 )
  • DATE                ( default format 0000-00-00 )
  • TIMESTAMP      ( default format 0000-00-00 00:00:00 )

PHP code:

  1.       DATE ->  $mysqldate = date( ‘Y-m-d’ );
  2.       DATETIME, TSTAMP  -> $mysqldate = date( ‘Y-m-d H:i:s’);

Now maybe you have have read some date field from MySql table and want to convert it to PHP date

  • $phpdate = strtotime( $mysqldate );

Tags: , , , , ,

Comments are closed.