Videos
"MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format." This is from mysql site. You can store only this type, but you can use one of the many time format functions to change it, when you need to display it.
Mysql Time and Date functions
For example, one of those functions is the DATE_FORMAT, which can be used like so:
SELECT DATE_FORMAT(column_name, '%m/%d/%Y %H:%i') FROM tablename
Use DATE_FORMAT function to change the format.
SELECT DATE_FORMAT(CURDATE(), '%d/%m/%Y')
SELECT DATE_FORMAT(column_name, '%d/%m/%Y') FROM tablename
Refer DOC for more details
Convert the output from calendar into date format like this
$cal_date=17-08-2012;
$date=date('Y-m-d',strtotime($cal_date));
echo $date; //gives date as 2012-08-17
Now you can insert this date into mysql and do comparisons
select str_to_date('31-12-2012', '%d-%m-%Y')
See STR_TO_DATE
This can be done using STR_TO_DATE.
Example:
INSERT INTO useless_table (id, date_added) VALUES(
1, STR_TO_DATE('03/08/2009', '%m/%d/%Y'));
EDIT: Please also consider MarkR's solution, because it's the right thing to do[tm].
MySQL support ISO-8601 date/time values, and no others. If you need to use some other whacky format (for example, because you have American customers who expect wonky dates), you need to do the conversion yourself.
Just live with it, ISO-8601 is the one true date format.
Here is an example on how I imported the following table (see: http://www.sqlcourse2.com/items_ordered.html)
customerid order_date item quantity price
10330 30-Jun-1999 Pogo stick 1 28.00
10101 30-Jun-1999 Raft 1 58.00
...
into my DB:
create table items_ordered (
customerid int(6),
order_date date,
item varchar(30),
quantity int(6),
price float(6,2)
);
LOAD DATA INFILE '/home/korulis/Documents/sqltut2 - items_ordered.csv'
IGNORE INTO TABLE items_ordered
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'-- '\r\n' or '\n'
IGNORE 1 LINES
(customerid, @var1, item, quantity, price)
SET order_date = STR_TO_DATE(@var1,'%d-%b-%Y');
You don't really want to do that.
What you really want is to store the date inside a DATE type column with the default format YYYY-MM-DD and leave your application to format the date as you wish.