[英]Get Current Month
This is sample my database: 这是我的数据库示例:
status date 状态日期
Q 2012-08-02. 问2012-08-02。
Here if i run my application means i wish to display 2. This is do following information. 在这里,如果我运行我的应用程序,则意味着我希望显示2。这是以下信息。 - check the database current month+status=Q after display how many matched information is totally you are got.for example totally 2 means the output is displayed 2.
-在显示总共获得了多少条匹配的信息后,检查数据库当前月+状态= Q ,例如,总计2表示显示输出2。
Already i done get the total count value for current date+status=Q information.it is successfully completed. 已经我做获得当前日期+状态总计数值= Q information.it成功完成。 Here i have use this code:
在这里,我使用此代码:
public class RetailerWs {
public int data(){
int count=0;
//count++;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager
.getConnection("jdbc:mysql://localhost:3306/pro","root","");
PreparedStatement statement = con
.prepareStatement("select * from orders where status='Q' AND date=CURDATE()");
ResultSet result = statement.executeQuery();
while(result.next()) {
// Do something with the row returned.
count++; //if the first col is a count.
}
}
catch (Exception exc) {
System.out.println(exc.getMessage());
}
return count;
}
}
the another class is: 另一类是:
public class Demo {
public static void main(String[] args){
RetailerWs obj = new RetailerWs();
System.out.println(obj.data());
}
}
the above code for get the information for current date + status=Q . 上面的代码用于获取当前日期+ status = Q的信息 。 please help me how is write the code for current month + status=Q ....
请帮助我如何编写当前月份的代码+ status = Q ....
It should be: 它应该是:
select * from orders where status='Q' AND MONTH(date) = MONTH(CURDATE())
See THIS for more information on the date and time functions of MySQL. 有关MySQL的日期和时间功能的更多信息,请参见THIS 。
For the week, try: 本周,请尝试:
select * from orders where status='Q' AND WEEK(date) = WEEK(CURDATE())
For the week in THIS year, try: 对于今年的一周内,尝试:
select * from orders where status='Q' AND WEEK(date) = WEEK(CURDATE()) AND YEAR(date) = YEAR(CURDATE())
To have it all in one check use: 要一次检查所有内容,请使用:
select * from orders where status='Q' AND YEARWEEK(date) = YEARWEEK(CURDATE())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.