将数值转换为日期时间 [英] Converting a numeric value to date time

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

问题描述

我正在使用SQL Server2012。数据集中的日期列如下所示: 41547 。该列位于 nvarchar(255)中。我想将其转换为如下形式: yyyy-mm-dd hh:mm:ss (例如: 2013-09-14 12:23 :23.98933090 )。但是我做不到。我正在使用以下代码:

I am working in SQL Server 2012. My date column in a data set looks like this: 41547. The column is in nvarchar (255). I want to convert it to something like this: yyyy-mm-dd hh:mm:ss (Example: 2013-09-14 12:23:23.98933090). But I can not do this. I am using following code:

select convert(datetime, date_column, 6)

但这给出了以下错误:

Msg 241, Level 16, State 1, Line 1 Conversion failed when converting
date and/or time from character string.

我在做什么错了?

推荐答案

我刚刚找到了实现此目的的方法。

I have just found the way to do this.

首先,我必须将nvarchar转换为int,然后将其转换为int迄今为止的时间。我使用了以下代码:

First I have to covert the nvarchar to int then I have to convert it to date time. I have used following code:

Select convert(datetime, (convert (int, [date_column])), 6) as 'convertedDateTime' from mytable

这篇关于将数值转换为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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