Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Date 1

Status
Not open for further replies.

jshanoo

Programmer
Apr 2, 2002
287
IN
Hi,
I am inserting records into tables with 'Date' as one of the datatype.
value i see in table is '0000-00-00'.

How will i insert date into table with original value.

Regards
John

*** Even the Best, did the Bad and Made the Best ***

John Philip
 
if you mean how will I insert 31/12/2003 type date into a date field, you won't , you need to format it as a mysql style date to be able to use all of myslqs date functions on the field.

In this case I normally add a varchar(10) field (old_date) and a DATE field (new_date), and then convert the date from the old format to mysql format.

update my_table set new_date=date_format(concat(@year:=substring(old_date ,7,2),@month:=substring(old_date ,4,2),@day:=substring(old_date ,1,2)), '%Y-%m-%d');

*note, This is for dd/mm/yy but you can ove the elements around in the UPDATE query.

** Added this as a FAQ at long last :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
MySql accepts date as yyyy-mm-dd. The supported range is '1000-01-01' to '9999-12-31'. if u enter wrong date or ur column is null type then u canget the value as 0000-00-00



[ponder]
----------------
ur feedback is a very welcome desire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top