我有我想插入到表中的数据。样本数据MM/DD/YYYY
+ 1 天和12:00:00 PM
基本上我需要的是插入当前日期 + 1 天和 12:00:00 PM 的特定时间。
我的代码是这样的:
DECLARE @MyEstimatedDate as varchar(100) ---TEMPORARY CONTAINER
DECLARE @MyEstimatedDate1 as varchar(100) ---TEMPORARY CONTAINER
DECLARE @MyEstimatedDate2 as varchar(100) ---TEMPORARY CONTAINER
DECLARE @MyEstimatedDate3 as DATETIME ---FINAL DATA NEEDED. This is the data I want inserted.
SET @MyEstimatedDate = DATEADD(day,1,GETDATE())
SET @MyEstimatedDate1 = CONVERT(VARCHAR(100),@MyEstimatedDate,101)
SET @MyEstimatedDate2 = @MyEstimatedDate1 + ' 12:00:00 PM'
SET @MyEstimatedDate3 = cast(@MyEstimatedDate2 as datetime) ---I believe this is the error
我得到的错误信息:
将 char 数据类型转换为 datetime 数据类型会导致 datetime 值超出范围。