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

Reply

Join Date: Apr 2009
Posts: 19
Reputation: ajay_p5 is an unknown quantity at this point 
Solved Threads: 0
ajay_p5 ajay_p5 is offline Offline
Newbie Poster

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

 
0
  #1
Oct 19th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,384
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 167
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso
 
2
  #2
Oct 19th, 2009
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
a unix timestamp is easier
apologies
other people with less rigid literal minds have little trouble with setting up the processing to run queries on sql date types
Last edited by almostbob; Oct 19th, 2009 at 3:10 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 51
Reputation: baki100 is an unknown quantity at this point 
Solved Threads: 11
baki100 baki100 is offline Offline
Junior Poster in Training
 
-1
  #3
Oct 20th, 2009
try to convert it as a date in the insert statement by using this function:
str_to_date('30 Jun 2009','%d %b %Y')
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC