在SQL中将字符串转换为Datetime对象 [英] Convert String to Datetime Object in SQL

查看:271
本文介绍了在SQL中将字符串转换为Datetime对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MySQL 5.6 ,并且具有类似以下之一的日期时间戳:2015-01-28 08:30:02:843000.当前,它们存储为字符串.我试图更改表以使其成为日期时间对象,但命令失败.我对SQL很粗糙,将这些转换为datetime对象的查询是什么?我是否需要以某种方式删除毫秒?还是将最后一个冒号转换为句号?

I'm using MySQL 5.6 and I have datetime stamps like one of this: 2015-01-28 08:30:02:843000. Currently, they are stored as strings. I tried to alter the table to make this into datetime objects but the command failed. I'm rough with SQL, what would be the query to convert these to datetime objects? Do I need to remove the milliseconds somehow? Or convert the last colon to a period?

推荐答案

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_str-to-date 'STR_TO_DATE(str,format)'

应该为您解决问题.你想做什么 A)创建新字段(日期) B)UPDATE表设置新字段转换(旧字段) C)你完成了

Should do the trick for you. What you want to do A) Create New Field (date) B) UPDATE table set new field convert(old field) C) You're done

这篇关于在SQL中将字符串转换为Datetime对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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