C#获取指定日期的星期,和sql server中根据指定日期取出来的相对应

private int GetWeek(DateTime now)
{
      System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();
      int weekOfYear = gc.GetWeekOfYear(now, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
      return weekOfYear;
}

C#:GetWeek(GetWeek(DateTime.Now))

对应

SQL:SELECT DATEPART(WEEK,GETDATE())

你可能感兴趣的:(SQL Server)