比较日期 [英] Compare between dates
本文介绍了比较日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jsp和msaccess。在表单中,我有一个dd / mm / yy格式的日期字段。它存储在TEXT中的表中。我想显示当前日期和当前日期之前2周之间的所有行。我的代码不适用于> <功能。 ONlY =有效请帮助。
我的代码在下面
Iam using jsp and msaccess. In form I have have a date field in dd/mm/yy format.It is stored in table in TEXT. I want to display all the rows between current date and 2 weeks ahead of current date. My code doestnot work for between and > < function. ONlY = works Please help.
My code is below
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%java.text.DateFormat df = new java.text.SimpleDateFormat("dd/MM/yy"); %>
<%
Calendar cal = Calendar.getInstance();
// out.println("Now : " + cal.get(Calendar.DATE));
String s=cal.getTime().toString();
String formatted = df.format(cal.getTime());
out.println(formatted);
int daysToIncrement = +14;
cal.add(Calendar.DATE, daysToIncrement);
String s1=df.format(cal.getTime());
out.println(s1);
// out.println("Date after increment: " + cal.getTime());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sSql="Select ADDRESS,FinancialYear,Todate from details where Todate BETWEEN '"+formatted+"' and '"+s1+"'";
String sDBQ = "C://Users/vishnu/Documents/amc.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + sDBQ + ";DriverID=22;READONLY=true";
Connection cn = null;
Statement st = null;
ResultSet rs = null;
try {
cn = DriverManager.getConnection( database ,"","");
st = cn.createStatement();
rs=st.executeQuery(sSql);
%>
<table border='2' vspace='80'>
<%
out.println("<thead>");
out.println("<tr>");
out.println("<th>Customer Name</th>");
out.println("<th>Financial Year</th>");
out.println("<th>To Date</th>");
out.println("</tr>");
out.println(" </thead>");
String add="";
String fin="";
String to="";
while(rs.next())
{
add=rs.getString(1);
fin=rs.getString(2);
to=rs.getString(3);
%>
<tr>
<td><%=add%></td>
<td><%=fin%></td>
<td><%=to%></td>
<%
}
out.close();
}
catch(Exception e)
{
out.println(e);
}
%>
</table>
</body>
</html>
更正了代码块和一些html标签
Code blocks and some html tags corrected
推荐答案
这篇关于比较日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文