将VARCHAR时间戳转换为TIMESTAMP? [英] Convert VARCHAR timestamp to TIMESTAMP?

查看:2935
本文介绍了将VARCHAR时间戳转换为TIMESTAMP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL数据库中有一个表格17:16:28 Sep 13,2011 PDT的时间戳。数据库中的字段类型为VARCHAR。我想将这个VARCHAR转换为MySQL中类型为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆