1 public static int weekoftheyear ()
2 {
3 // get
4 cultureinfo myci = new cultureinfo ("ZH-CN ");
5 system. Globalization. Calendar mycal = myci. calendar;
6
7 // Date Format
8. calendarweekrule mycwr = myci. datetimeformat. calendarweekrule;
9 dayofweek myfirstdow = myci. datetimeformat. firstdayofweek;
10
11 // this week is week mycal. getweekofyear (datetime. Now, mycwr, myfirstdow)
12 INT thisweek = mycal. getweekofyear (datetime. Now, mycwr, myfirstdow );
13 return thisweek;
14}
In SQL statements, how do I obtain the week of the current year?
For example, I did this to obtain the weekly ranking function.
Table weekstat
Userno int not null,
Author varchar (64) not null,
Year int not null,
Week int not null,
Postcount int
Query statement
Select postcount as returnnum, author
From weekstat
Where (year = datepart (year, getdate () and (week = datepart (Week, getdate ()))
Order by postcount DESC
In this way, we can get the weekly ranking, and the performance is more than a hundred times higher than that of group.
The group by data has timed out. There is no IO operation or CPU usage at all.