我想要获取员工的生日。从指定的月份 例如:对于" 8月和#34;我想从日期14 - 20
获取数据我很难过,因为每个人都有不同的出生年份。
这是我尝试过的。但是不起作用,我也搜索互联网,但没有一个线索。
Dim monthName As String = cb_month.Text 'from combobox that has list of months
Dim monthNumber = DateTime.ParseExact(monthName, "MMMM", CultureInfo.CurrentCulture).Month
Dim fromday = CInt(cb_dayfrom.Text)
Dim todate = cb_dayto.Text
' Here's my query
query = "SELECT empID AS 'ID', Name, Cast(Birthday AS DATE) FROM empInfo BETWEEN '%" & monthNumber & "-" & fromday.ToString & "%' AND '%" & monthNumber & "-" & todate & "%'"
哦,另一个问题是:
Cast(生日日期)行返回日期和时间,我该如何摆脱这个?
sql中生日的数据类型为日期
答案 0 :(得分:0)
最后!找到了我的问题的答案..
Dim monthNumber As Integer = DateTime.ParseExact(cb_month.Text, "MMMM", CultureInfo.CurrentCulture).Month
Dim fromdate As Integer = CInt(cb_dayfrom.Text)
Dim todate As Integer = CInt(cb_dayto.Text)
query = "SELECT empID AS 'ID', Name, CONVERT(VARCHAR(10),Birthday,101) FROM empInfo " & _
"WHERE DATEPART (month, Birthday) = " & monthNumber & _
" AND (DATEPART (day, Birthday) Between " & fromdate & " AND " & todate & ")"