简体   繁体   中英

Convert data type varchar to data type date in MySQL (one Table)

I have data on TGLBAYAR column in "pelayanan" table. I want to convert them to type data DATE on new column BAYAR .

I already have column BAYAR with data type DATE which the value is NULL.

How can I solve this problem in MySQL?

The data on TGLBAYAR is 31/07/2014 -> dd/mm/yy

这样的事情应该可以解决问题:

SELECT convert(datetime, pelayanan.TGLBAYAR , 103)

Use this code

SELECT convert(datetime, pelayanan.TGLBAYAR , 101)

Or

SELECT CAST(TGLBAYAR AS DATETIME) AS TGLBAYAR FROM pelayanan

You can convert using str_date(str,format)

SELECT STR_TO_DATE('04/31/2004', '%m/%d/%Y');

OUTPUT

'2004-04-31'

for more details use this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM