[英]Convert timestamp (int) to smalldatetime (t-sql)
I have a MySQL -Database with several rows. 我有一个MySQL -Database有几行。 In that environment, I stored the current time as a Timestamp (
int
). 在这种环境中,我将当前时间存储为时间戳(
int
)。
Now I need to migrate my data from a MySQL to a T-SQL-Database. 现在,我需要将数据从MySQL迁移到T-SQL-Database。 I'm running SQL-Server 2008 .
我正在运行SQL-Server 2008 。
I checked several approaches, but couldn't come up with a way which transforms my int into a smalldatetime format. 我检查了几种方法,但无法提出将int转换为smalldatetime格式的方法。
Is there a build-in function for this? 是否有内置功能? Is this even doable alone in a statement?
仅凭声明这是否可行? I really don't want to write a PHP-snippet, which converts the timestamp to the desired format.
我真的不想写PHP片段,将时间戳转换为所需的格式。
Thanks in advance 提前致谢
As per the documentation , smalldatetime
uses the following format: 根据文档 ,
smalldatetime
使用以下格式:
DECLARE @smalldatetime smalldatetime = '1955-12-13 12:43:10';
So, we need to convert the MySQL
timestamp into date
and format it in the above format to get smalldatetime
. 因此,我们需要将
MySQL
时间戳转换为date
并以上述格式对其进行格式化,以获取smalldatetime
。 This can be done by using FROM_UNIXTIME
and DATE_FORMAT
functions of MySQL
, eg: 这可以通过使用
MySQL
FROM_UNIXTIME
和DATE_FORMAT
函数来完成,例如:
DATE_FORMAT(FROM_UNIXTIME(timestamp_column), '%e %b %Y') AS 'smalldatetime';
Here's the SQL Fiddle . 这是SQL Fiddle 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.