我如何获得星期几?使用SQL或VB.net [英] How can i Get the week number? using SQL or VB.net

查看:122
本文介绍了我如何获得星期几?使用SQL或VB.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我如何获得星期几?

例如一年中有53周,如果我检查3月1日的星期数,则为第9周,如果我通过日期即3月8日,则为一年的第10周.

Hi,
How can i Get the week number?

e.g. there are 53 weeks in year and if i check the week numer of 1-March then its 9th week and if i pass the date i.e 8th-march then its 10 week of the year.

推荐答案

您可能已经注意到,DateTime没有WeekNumber属性.但是,这可在CultureInfo日历中使用:)

因此,我们首先创建一个文化变量,并用当前的文化填充它.

然后,您可以首先在日历中配置更多规则,例如应将星期几视为第一天.

这是适合您的代码示例:)

祝你好运

As you might have noticed DateTime does not have a WeekNumber property. This however is available inside the CultureInfo calendar :)

So we first create a culture variable and fill it with the current culture.

Then you can first configure some more rules inside the calendar like what day of the week it should concider as the first day.

Here a code example for you :)

Good luck

DateTime dateTime = DateTime.Parse("08-03-2010");

System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CurrentCulture;

int intWeek = culture.Calendar.GetWeekOfYear(dateTime, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);


这篇关于我如何获得星期几?使用SQL或VB.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆