954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to insert date in string format into MYSQL table as DATE data type

Hello people,

Well The problem that I am facing is:
I have a date in string format like 30 Jun 2009, how can I insert it into MYSQL table as DATE data type?

I created the table and declare data type for Date column as DATE, when I insert 30 Jun 2009 as a value into the table, it becomes 00:00:00. What should I do to avoid this error. Please suggest. Thanks

Ajay

ajay_p5
Light Poster
29 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

depending on the language used as the front end to the mysql back end,
php $date=strtotime('string');
asp $date=DateTime.Parse('string');
in sql getdate($date)

don't use those codes look em up, I havent, so there will be errors

sql date format sux, is explained here http://www.tizag.com/sqlTutorial/sqldate.php
hugely sux
personal view[INDENT]a unix timestamp is easier [/INDENT]apologies
other people with less rigid literal minds have little trouble with setting up the processing to run queries on sql date types

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

try to convert it as a date in the insert statement by using this function:
str_to_date('30 Jun 2009','%d %b %Y')

baki100
Junior Poster in Training
79 posts since Apr 2009
Reputation Points: 12
Solved Threads: 14
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You