数据库函数判断本周,本年,本月,本天,本季度
程序员文章站
2022-06-15 22:45:21
...
//自定义:本周、本月、本季度、本年,本天查询条件
public Criteria andTimeSearch(String time){
//时间范围
if(StringUtils.isNotEmpty(time)){
if(time.equals("1")){
StringBuffer sb = new StringBuffer("YEARWEEK(date_format(create_date,'%Y-%m-%d')) = YEARWEEK(now())");
addCriterion(sb.toString());
}
if(time.equals("2")){
StringBuffer sb = new StringBuffer("DATE_FORMAT( create_date, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )");
addCriterion(sb.toString());
}
if(time.equals("3")){
StringBuffer sb = new StringBuffer("QUARTER(create_date)=QUARTER(now())");
addCriterion(sb.toString());
}
if(time.equals("4")){
StringBuffer sb = new StringBuffer("YEAR(create_date)=YEAR(NOW())");
addCriterion(sb.toString());
}
if(time.equals("5")){
StringBuffer sb = new StringBuffer("DATE_FORMAT(create_date,'%Y%m%d') = DATE_FORMAT(now(),'%Y%m%d')");
addCriterion(sb.toString());
}
}
return this;
}
上一篇: c#中用键盘控制发送的方法
下一篇: js获取本周,本月,本年