[英]MySQL: extracting date from string
Is it possible to get the date in mysql from this string: Thu Mar 10 005758 EST 2016 ? 是否可以通过以下字符串在mysql中获取日期:Thu Mar 10 005758 EST 2016? I'd like to get the date in mm/dd/yy format.
我想以mm / dd / yy格式获取日期。
Use STR_TO_DATE() to convert the original string to a date: 使用STR_TO_DATE()将原始字符串转换为日期:
mysql> SELECT STR_TO_DATE('Thu Mar 10 005758 EST 2016', '%a %b %e %H%i%s EST %Y');
+---------------------------------------------------------------------+
| STR_TO_DATE('Thu Mar 10 005758 EST 2016', '%a %b %e %H%i%s EST %Y') |
+---------------------------------------------------------------------+
| 2016-03-10 00:57:58 |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)
Then use DATE_FORMAT() to format it as you wanted 'mm/dd/yy': 然后使用DATE_FORMAT()将其格式化为'mm / dd / yy':
mysql> SELECT DATE_FORMAT( STR_TO_DATE('Thu Mar 10 005758 EST 2016', '%a %b %e %H%i%s EST %Y'), '%m/%d/%y');
+-----------------------------------------------------------------------------------------------+
| DATE_FORMAT( STR_TO_DATE('Thu Mar 10 005758 EST 2016', '%a %b %e %H%i%s EST %Y'), '%m/%d/%y') |
+-----------------------------------------------------------------------------------------------+
| 03/10/16 |
+-----------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.