工作中需要计算当前时间对应的本周一、上周一,以下是对应代码:

            var datetime = DateTime.Now;

            int weeknow = Convert.ToInt32(datetime.DayOfWeek);

            //本周一  
            int currentMonday = (weeknow == 0 ? 6 : (weeknow - 1));
            //上周一
            int lastMonday = (weeknow == 0 ? 13 : (weeknow + 6));

            string FirstDay = datetime.AddDays(-currentMonday).ToString("yyyy-MM-dd");
            string LastFirstDay = datetime.AddDays(-lastMonday).ToString("yyyy-MM-dd");

  直接写SQL,没有找到很好的简单有效解决方案,如果有使用SQL解决的,请回复告知。

相关文章:

  • 2021-09-12
  • 2021-05-30
  • 2021-11-29
  • 2021-12-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
相关资源
相似解决方案