发布网友 发布时间:2022-04-29 15:20
共2个回答
热心网友 时间:2022-04-12 11:02
这个看你用的什么数据库,还有你的自动是什么数据类型:
比如oracle,日期类型:
select * from tablea where datecol between add_months(trunc(sysdate(),-3) and trunc(sysdate()
如果是sqlserver
select * from tablea where datecol between dateadd(mm,-3,getdate()) and getdate();
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript" language="javascript" >
function get3MonthBefor(){
var resultDate,year,month,date,hms;
var currDate = new Date();
year = currDate.getFullYear();
month = currDate.getMonth()+1;
date = currDate.getDate();
hms = currDate.getHours() + ':' + currDate.getMinutes() + ':' + (currDate.getSeconds() < 10 ? '0'+currDate.getSeconds() : currDate.getSeconds());
switch(month)
{
case 1:
case 2:
case 3:
month += 9;
year--;
break;
default:
month -= 3;
break;
}
month = (month < 10) ? ('0' + month) : month;
resultDate = year + '-'+month+'-'+date+' ' + hms;
return resultDate;
}
document.write(get3MonthBefor());
</script>
</head>
<body>
</body>
</html>
运行效果图如下:
热心网友 时间:2022-04-12 12:20
select * from 表 where 日期字段 between getDate() and DATEADD(month, -2, getDate())