我正在尝试在 VB 中转换此 SQL 语句,但没有成功。任何人都可以帮忙吗?
declare @factor as int
declare @Date as varchar(30)
set @factor = (Cast(Convert(datetime, @Date) as int) - 33975)-
(28 * ((Cast(Convert(datetime, @Date) as int) - 33975)/28))
我正在尝试在 VB 中转换此 SQL 语句,但没有成功。任何人都可以帮忙吗?
declare @factor as int
declare @Date as varchar(30)
set @factor = (Cast(Convert(datetime, @Date) as int) - 33975)-
(28 * ((Cast(Convert(datetime, @Date) as int) - 33975)/28))
首先,您需要将字符串值解析为DateTime
. 然后计算nr。从 1900-01-01 到该日期的天数。
Dim str = "2005-11-14"
Dim dateValue = DateTime.ParseExact(str, "yyyy-MM-dd",
CultureInfo.InvariantCulture, DateTimeStyles.None)
Dim baseDate = New DateTime(1900, 1, 1)
Dim intValue = (dateValue - baseDate).TotalDays
您可以应用数学运算
Dim factor = intValue - 33975 - (28 * (intValue - 33975) / 28)