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')
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)
in both cases
select * table1
will give you:
| date | ------------------------------------ | september, 05 2013 00:00:00+0000 |
Comments
Post a Comment