简体   繁体   English

在MySQL中将8位数字转换为日期类型

[英]convert 8-digit number to date type in mysql

I have a table in, MySQL 5.5, having an INT column which is actually a 8-digit number representing a date value in the format YYYYMMDD 我在MySQL 5.5中有一个表,具有一个INT列,该列实际上是一个8位数字,表示日期值,格式为YYYYMMDD

How can I convert this column into a DATE type so as for easy compare with other DATE column in other table? 如何将该列转换为DATE类型,以便与其他表中的其他DATE列进行比较?

Use mysql STR_TO_DATE 使用mysql STR_TO_DATE

The STR_TO_DATE() converts the str string into a date value based on the fmt format string. STR_TO_DATE()根据fmt格式字符串将str字符串转换为日期值。

SELECT STR_TO_DATE('20141012','%Y%m%d') FROM `table`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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