sql语句中,我怎么计算一个月份是第几个季度的?例:7月份,用一个算法,直接知道他是属于第三季度?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql语句中,我怎么计算一个月份是第几个季度的?例:7月份,用一个算法,直接知道他是属于第三季度?相关的知识,希望对你有一定的参考价值。
select casewhen month between 1 and 3 then '一季度'
when month between 4 and 6 then '二季度'
when month between 7 and 9 then '三季度'
when month between 10 and 12 then '四季度'
end as 季度
from table
这样就可以了 参考技术A select CEILING(convert(real,7)/3)
=======================
把7换成你要算的月份就可以了本回答被提问者采纳 参考技术B DateName (interval,date) 返回日期date中,interval指定部分所对应的字符串名称
参数 interval的设定值如下:
Quarter Qq q 季 1 ~ 4
js根据当前时间获取当前季度,月份,和第几周
function jidu()
{
var getMonthWeek = function (a, b, c) {
var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate();
return Math.ceil( (d + 6 - w) / 7 );
};
var getYearWeek = function (a, b, c) {
var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1),
d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
return Math.ceil( (d + ((date2.getDay() + 1) - 1)) / 7 );
};
var today = new Date();//获取当前时间
var y = today.getFullYear();
var m = today.getMonth()+1;
var d = today.getDate();
//document.write("今天是:",y,"-", m, "-", d, "<br/>");
//document.write( "今天是",y,"年的第 ", getYearWeek(y, m, d), " 周<br/>" );
//document.write( "今天是",m,"月的第 ", getMonthWeek(y, m, d), " 周<br/>" );
var quarter = "";
var result = getYearWeek(y, m, d);
if (m <4) {
quarter = 1;
week = result;
} else if (m < 7) {
quarter = 2;
week = result - getYearWeek(y, 4, 1);
var day = new Date(y, 4, 1);
if (day.getDay() > 1) {
week += 1;
}
} else if (m < 10) {
quarter = 3;
week = result - getYearWeek(y, 7, 1);
var day = new Date(y, 7, 1);
if (day.getDay() > 1) {
week += 1;
}
} else {
quarter = 4;
week = result - getYearWeek(y, 10, 1);
var day = new Date(y, 10, 1);
if (day.getDay() > 1) {
week += 1;
}
}
//document.write( "今天是第",quarter,"季度的第 ", week, " 周" );
document.write( quarter);
}
以上是关于sql语句中,我怎么计算一个月份是第几个季度的?例:7月份,用一个算法,直接知道他是属于第三季度?的主要内容,如果未能解决你的问题,请参考以下文章