获取今天是今年得第几周得函数
1public static int WeekOfTheYear()
2 {
3 //获取
4 CultureInfo myCI = new CultureInfo("zh-CN");
5 System.Globalization.Calendar myCal = myCI.Calendar;
6
7 //日期格式
8 CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
9 DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
10
11 //本周为第myCal.GetWeekOfYear( DateTime.Now, myCWR, myFirstDOW )周
12 int thisWeek=myCal.GetWeekOfYear( DateTime.Now, myCWR, myFirstDOW );
13 return thisWeek;
14 }
SQL语句中如何获得当前为这一年的第几周呢?2 {
3 //获取
4 CultureInfo myCI = new CultureInfo("zh-CN");
5 System.Globalization.Calendar myCal = myCI.Calendar;
6
7 //日期格式
8 CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
9 DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
10
11 //本周为第myCal.GetWeekOfYear( DateTime.Now, myCWR, myFirstDOW )周
12 int thisWeek=myCal.GetWeekOfYear( DateTime.Now, myCWR, myFirstDOW );
13 return thisWeek;
14 }
比如获得周排行的功能,我是这么做的
表WeekStat
UserNO int not null,
Author varchar(64) not null,
Year int not null,
Week int not null,
PostCount int
查询语句
SELECT PostCount as ReturnNum, Author
FROM WeekStat
WHERE (Year = DATEPART(Year, GETDATE())) AND (Week = DATEPART(Week, GETDATE()))
ORDER BY PostCount DESC
这样就可以得到周排行了,性能比以前哥们用group by的要高不只百倍。
group by的在100W数据的时候已经超时了。这个根本就没有多少IO操作和CPU占用
作者:jillzhang
出处:http://jillzhang.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://jillzhang.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。