将SQL表达式转换为VB

时间:2012-11-01 21:53:26

标签: sql vb.net visual-studio-2010

我试图在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))

1 个答案:

答案 0 :(得分:2)

首先,您需要将字符串值解析为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)