将VARCHAR时间戳转换为TIMESTAMP? [英] Convert VARCHAR timestamp to TIMESTAMP?
问题描述
我尝试了一些本网站其他地方提出的解决方案,例如使用string_to_time函数,但是这些解决方案都是从不同类型的时间戳开始的。
如何将上面提到的VARCHAR时间戳转换为MySQL认可的TIMESTAMP,这样我可以
您可以使用 STR_TO_DATE 函数,请尝试:
SELECT STR_TO_DATE(17:16:28 2011年9月13日PDT,'%H:%i:%s%b%d,%Y太平洋夏令时');
编辑:
code> SELECT STR_TO_DATE(field_name,'%H:%i:%s%b%d,%Y PDT')AS new_time
FROM table_name;
I have a time stamp of the form "17:16:28 Sep 13, 2011 PDT" in a MySQL database. The type of the field in the database is VARCHAR. I would like to convert this VARCHAR to a field of type TIMESTAMP in MySQL.
I tried a few solutions suggested elsewhere on this site, such as using a string_to_time function, but these solutions all start from a different type of timestamp.
How do I convert the VARCHAR timestamp mentioned above to a TIMESTAMP recognised by MySQL, in such a way that I can sort my data by date?
You can do this by using STR_TO_DATE function in MySQL, try this:
SELECT STR_TO_DATE("17:16:28 Sep 13, 2011 PDT", '%H:%i:%s %b %d, %Y PDT');
EDIT:
SELECT STR_TO_DATE(field_name, '%H:%i:%s %b %d, %Y PDT') AS new_time
FROM table_name;
这篇关于将VARCHAR时间戳转换为TIMESTAMP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!