从datetimepicker获取周数

时间:2014-09-09 11:54:14

标签: mysql vb.net

如何获取datetimepicker中的星期数就像在Mysql中一样只使用函数WEEK() 它会返回周数,就像那样简单。

例如

datetimepicker1.text = "9/9/2014"
'returns 36

just like in mysql. example.

WEEK(9/9/2014)
`returns 36

1 个答案:

答案 0 :(得分:3)

您可以使用Calendar.GetWeekOfYear

Dim dt = datetimepicker1.Value 
Dim dateInfo = Globalization.DateTimeFormatInfo.CurrentInfo
Dim c = dateInfo.Calendar

Dim week = c.GetWeekOfYear(dt, dateInfo.CalendarWeekRule, dateInfo.FirstDayOfWeek)