MySQL:如何计算从特定日期算起的星期数? [英] MySQL: How to calculate weeks out from a specific date?
本文介绍了MySQL:如何计算从特定日期算起的星期数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从MySQL select语句中的某个日期开始计算周数.其中一个表中有一个日期列,我需要计算该日期有几周.
I need to calculate the weeks out from a date in my MySQL select statement. There is a date column in one of the tables, and I need to calculate how many weeks away the date is.
SELECT EventDate, (calculation) AS WeeksOut FROM Events;
示例:
- 6天之内,周数= 0
- 7天之内,几周= 1
- 13天之内,几周= 1
- 14天之内,几周= 2
推荐答案
使用 WEEKS的问题在于,对于跨越1月1日的日期,它不会返回正确的结果.
The problem with WEEKS is that it won't return correct results for dates that cross over January 1st.
0
是 ROUND
函数.
这篇关于MySQL:如何计算从特定日期算起的星期数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文