是否可以将mySQL设置为星期六作为一周的开始? [英] Is it possible to set mySQL to have a saturday as the start of the week?

查看:250
本文介绍了是否可以将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.

我已经了解到,设置default_week_format会有所帮助,但我认为这对我不起作用,因为这仅适用于特定报告,而不是整个系统.

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.

我还有其他选择吗?

推荐答案

从Tomasz答案中的链接注释中获取:

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

这篇关于是否可以将mySQL设置为星期六作为一周的开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆