格式(CDate())结果给出错误的结果

时间:2014-04-10 03:40:13

标签: vb.net

我在vb中有以下代码

Dim sStart As String, sEnd As String
sStart = ComboBoxYear.List(ComboBoxYear.ListIndex) & "-" & ComboBoxMonth.List(ComboBoxMonth.ListIndex) & "-1"

sEnd = Format(DateAdd("M", 1, CDate(sStart)) - 1, "yyyy-MMM-dd")

现在我已经在VB.NET中将其更改为

sStart = Me.ComboBoxYear.SelectedItem.ToString() & "-" & ComboBoxMonth.SelectedItem.ToString() & "-1"
sEnd = Format(DateAdd("M", 1, CDate(sStart)) & -1, "yyyy-MMM-dd")

但是 sEnd 将结果作为' yyyy-MMM-dd'只是,我在我的代码中做错了。

1 个答案:

答案 0 :(得分:0)

尝试这样

sStart = Me.ComboBoxYear.SelectedItem.ToString() & "-" & 
ComboBoxMonth.SelectedItem.ToString() & "-1"
sEnd =Format(CDate(DateAdd("M", 1, CDate(sStart)) & -1), "yyyy-MMM-dd")

DateAdd("M", 1, CDate(sStart)) & -1

中添加CDate