有谁可以帮我转换1218100860到datetime ?
我试过这样的:
SELECT CONVERT(VARCHAR(11), DATEADD(s,1218100860, '1970-01-01 00:00:00'), 101)它的工作原理但是当我尝试这样时,它会抛出一个错误:
SELECT CONVERT(VARCHAR(11), DATEADD(s, rd.Request_Date, '1970-01-01 00:00:00'), 101) FROM dbo.RequestDetails rd其中Request_Date是必须将值转换为datetime的列,错误是:
参数数据类型varchar对于dateadd函数的参数2无效。
Can anyone please help me with converting 1218100860 to datetime?
I tried like this:
SELECT CONVERT(VARCHAR(11), DATEADD(s,1218100860, '1970-01-01 00:00:00'), 101)and it works but when I try like this, it throws an error:
SELECT CONVERT(VARCHAR(11), DATEADD(s, rd.Request_Date, '1970-01-01 00:00:00'), 101) FROM dbo.RequestDetails rdwhere Request_Date is the column where the the value has to be converted to datetime the error is:
Argument data type varchar is invalid for argument 2 of dateadd function.
最满意答案
我不知道你正在使用什么RDBMS(也许是sQL Server?),但是:
参数数据类型varchar对于dateadd函数的参数2无效
这意味着参数2( rd.Request_Date )不应该是varchar 。 因为在你的第一个例子中你使用了一个整数并且它有效,所以你似乎只需要将rd.Request_Date转换为整数,它应该可以工作,如下所示:
SELECT CONVERT(VARCHAR(11),DATEADD(s,CONVERT(INT, rd.Request_Date), '1970-01-01 00:00:00'),101 )I don't know what RDBMS you're using (maybe sQL Server?), but:
Argument data type varchar is invalid for argument 2 of dateadd function
This means that argument 2 (rd.Request_Date) should not be a varchar. Since in your first example you used an integer and it worked, then it seems you just have to convert rd.Request_Date to integer and it should work, like this:
SELECT CONVERT(VARCHAR(11),DATEADD(s,CONVERT(INT, rd.Request_Date), '1970-01-01 00:00:00'),101 )更多推荐
发布评论