header
 
     
 
pixel
pixel pixel

Convert current date to MySQL format

The date format for a MySQL database is YYYY-MM-DD (eg - 2003-12-31). For example, to display the current date to this format using PHP, use:
<?php
echo "Today's date in MySQL format is ".date('Y-m-d'mktime()); 
?>

Unhelpful Helpful Rating 2.9 (score out of 5, no. of ratings: 40)
Comments
Comment by akmal on 2004-07-15
first of all, the code will give errors. mktime() is used to make a unix timestamp for a date. i don't see the need for mktime() to generate today's date. also the quoting is wrong. the correct code will be: echo "Today's date in MySQL format is ".date('Y-m-d');

Comment by Shanmugasundaram on 2005-03-24
Very good

Comment by lakshmi on 2005-12-12
Tell me how to insert value into date datatype in mysql

Comment by heena on 2005-12-30
extremely helpful!!

Comment by Sanjeev Kumar on 2006-01-10
This code is not correct use this one

Comment by Sourav Bose on 2006-12-21
From Oracle table when i create *.txt file or *.csv file the date fields will returns dd-mon-yy format. But MySql is inserted yyyy-mm-dd. How can is possible for to insert date field. My code is in ASP.Another thing dd-mon-yy is return as string type.

Post a Comment
Name
Email
(optional)
Comment
RatingUnhelpful Helpful
Security Image* (this is just to prevent spam submissions)
Security Image