how to convert / insert dd-mm-yyyy to mysql date format

133 views
Skip to first unread message

ElectroMech

unread,
Jun 6, 2010, 11:36:27 PM6/6/10
to vglug
Dear All,

HOWTO INSERT DATE FORAMT DD-MM-YYYY TO MYSQL AS IT ACCPET DATE IN YYYY-MM-DD

We stuck up once to insert date which is in dd-mm-yyyy format in files and need to be inserted in mysql.

But mysql store date in yyyy-mm-dd.

As there are lots of previous data, we use following function to insert date in format of dd-mm-yyyy but mysql stored it as yyyy-mm-dd.

I hope this will help you.

mysql> insert into test1  values('11','test',str_to_date('04-10-2001','%d-%m-%Y'));
Query OK, 1 row affected (0.00 sec)

mysql> select * from test1;
+----+------+------------+
| id | data | date       |
+----+------+------------+
|  1 | test | NULL       |
|  2 | test | NULL       |
|  3 | test | 0000-00-00 |
|  4 | test | 0000-00-00 |
|  5 | test | 0000-00-00 |
|  6 | test | 2000-10-04 |
|  7 | test | NULL       |
|  8 | test | NULL       |
|  9 | test | NULL       |
| 10 | test | 2020-10-04 |
| 11 | test | 2001-10-04 |
+----+------+------------+
11 rows in set (0.00 sec)

mysql> insert into test1  values('11','test',str_to_date('04-10-2001','%d-%m-%Y'));

Thanks and Regards.

--
--
Nilesh Vaghela
ElectroMech
Redhat Channel Partner and Training Partner
404, Maulik arcade, Above Karnavati Pagarakha Bazar,
Nr. Mansi cross Road,
Satellite Rd, Ahmedabad
25, The Emperor, Fatehgunj, Baroda.
www.electromech.info




--
--
Nilesh Vaghela
ElectroMech
Redhat Channel Partner and Training Partner
404, Maulik arcade, Above Karnavati Pagarakha Bazar,
Nr. Mansi cross Road,
Satellite Rd, Ahmedabad
25, The Emperor, Fatehgunj, Baroda.
www.electromech.info

Reply all
Reply to author
Forward
0 new messages