Dear Sir/Madam,
I faced a new problem,In select statement i used a range of dates say for
example i searched from Date >='2006-01-01' and Date<= '2006-02-31' .It retrieved
from January 1 st till March 3 rd.But i only want to retrieve only till february
28 th or 29 th if it is a leap year.But it return till 3rd march.I think i used 31
in the day so it added 3 values and retrieve 3 values (i.e) till 3rd march..How
to solve this problem.Please Help me!!!!
Regards
Prasanna.B
|
>example i searched from Date >='2006-01-01' and Date<= '2006-02-31' .
>It retrieved from January 1 st till March 3 rd.
Yeah. Because there's no 2-31, and Java will think it's March 3rd.
Changed it to
Date >='2006-01-01' and Date< '2006-03-01'
or
month(Date)<=2 and year(Date)=2006
|
Sorry for the late reply
Actually im connecting to the database from a web page through jsp.I get the
dates from the web page through drop down list.So in the day field it will be 1
to 31 days,suppose a user selects,
Starting Date: day field:1 month field:1 and year field : 2006
Ending Date : day field:31 month field:3 and year field : 2006
We have to display only from 1st jan till 28 feb.
If i implemented as u said ,Date>='2006-01-01' and Date<'2006-03-01' it will
be okay for these two months (i.e)jan till feb. But, suppose a user want the
details from 21st march to 21st april how to do that since we use lesser than
symbol it will ignore the particular day. How to implement this please give me
a solution.
Regards
Prasann.B
|
>How to implement this please give me a solution.
Then your issue is which you haven't verified and corrected the wrong input date, for instance, 2006-02-30 and 2006-03-31:)
You can use the following code to correct your date:
private static final java.sql.Date fixDate(String year,String month,String day){
Calendar calendar1=Calendar.getInstance();
int y=Integer.parseInt(year);
int m=Integer.parseInt(month)-1;
int d=Integer.parseInt(day);
calendar1.set(y,m,d);
if(calendar1.get(Calendar.DAY_OF_MONTH)!=d){
calendar1.setTimeInMillis(calendar1.getTimeInMillis()-calendar1.get(Calendar.DAY_OF_MONTH)*86400000);
}
return new java.sql.Date(calendar1.getTimeInMillis());
}
|
Thank u for your reply
Instead of that i wrote java script to validate the dates and also to check
whether the starting date is greater than the ending date.But i don't know how
to make the submit button disable until the dates are valid (or) to send only
valid dates.Any idea? Please give me some suggestion.
Regards
Prasanna.B
|
function checkDate() {
var myDayStr = document.CheckDate.formDate.value;
var myMonthStr = document.CheckDate.formMonth.value;
var myYearStr = document.CheckDate.formYear.value;
var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;
/* Using form values, create a new date object
using the setFullYear function */
var myDate = new Date();
myDate.setFullYear( myYearStr, myMonthStr, myDayStr );
if ( myDate.getMonth() != myMonthStr ) {
alert( 'I\'m sorry, but "' + myDateStr + '" is NOT a valid date.' );
} else {
alert( 'Congratulations! "' + myDateStr + '" IS a valid date.' );
}
}
at http://www.csua.berkeley.edu/~jgwang/jsfunc02.htm
|
Thank you for your response.
I solved my problem..
HXTT tech support is very good in fast response and optimal solution.
Regards
Prasanna.B
|