mysql - How to insert date in a table with a different format? -


my problem here have date value 05/09/2013 in html text box cannot altered.

now sql accepts date format yyyy/mm/dd. while inserting textbox value sql database not support format , throws exception.

therefore question how insert textbox value different format sql database?

for instance code

insert table (date) value('"& date& "') 

input box has calender type textbox , sends date in 05/09/2013 format

update

for mysql use str_to_date()

insert table1 (date) select str_to_date('05/09/2013', '%d/%m/%y') 

sqlfiddle

based on comments query should like

sql = "insert shiftpatterns (sitenumber,shiftdate) select '"&sitenumber&"', 'str_to_date('"&shiftdate&"','%d/%m/%y')" 

original answer

for sql server use convert

insert table1 ([date]) select convert(datetime, '05/09/2013', 103) 

sqlfiddle

in both cases

select * table1 

will give you:

|                             date | ------------------------------------ | september, 05 2013 00:00:00+0000 | 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -