mysql 擷取上周1到周日的時間,mysql上周

來源:互聯網
上載者:User

mysql 擷取上周1到周日的時間,mysql上周

declare _LastWeekStartTime date; -- 上周開始時間declare _LastWeekEndTime date; -- 上周結束時間-- 因系統為星期日為每星期第一天 所以需要減1set @A = date_add(curdate(), interval -1 day);-- 算出本周星期一的日期set @B = subdate( @A,date_format(@A,'%w')-1);-- 因系統為星期日為每星期第一天 所以需要 減2 擷取上星期最後一天(上星期星期六)set @C = date_add(@B, interval -2 day);set _LastWeekStartTime = ( subdate(  @C,date_format( @C,'%w')-1));set _LastWeekEndTime = ( date_add(subdate(  @C,date_format( @C,'%w')-1), interval 6 day));

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.