select 
  date_format(subdate(now(),date_format(now(),'%w')-1),'%Y-%m-%d') 
from 
  dual
  • now()
    返回当前日期,也可以用current()
  • w%
    以数字的形式来表示日期为本周的第几天,0为周日,6为周六,以此类推
  • date_format(now(),‘%w’)
    返回当前日期为本周的第几天
  • subdate()
    从日期中减去指定的时间间隔,也可以用date_sub(date,INTERVAL expr type)
  • subdate(now(),date_format(now(),‘%w’)-1)
    从当前日期减去距离周一的天数,返回当前日期所在周的星期一
  • data_format(date,format)
    进行日期格式化,格式可自行设置
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐