mysql输出星期六,是否可以将mySQL设置为星期六作为一周的开始?

Is it possible to set mySQL to have a saturday as the start of the week?

I'm trying to run a query like:

SELECT DISTINCT(week(`date`))

FROM `table`

WHERE `date` BETWEEN '2010-08-14' AND '2010-08-27'

But the week starts on a Saturday, not Sunday or Monday. (It's for a pay period week, not a regular week)

It seems that the modes for the week function only offer Sunday or Monday as a starting date.

I've read that setting default_week_format can help but I don't think that will work for me as this is for specific reports only, not the entire system.

Do I have any other options?

解决方案

Cribbed from the comments from the link in Tomasz's answer:

Problem: To find week start and end

date with user specified start of the

week day and user specified date for

which the week is to be found.

date_sub(t.date, interval if(dayofweek(t.date)-$weekStartingDay >= 0, dayofweek(t.date)-$weekStartingDay, dayofweek(t.date)-$weekStartingDay+7) day) week_start

date_sub(t.date, interval if(dayofweek(t.date)-$weekStartingDay >= 0, dayofweek(t.date)-$weekStartingDay, dayofweek(t.date)-$weekStartingDay+7) - 6 day) week_end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值