Urgent help on range of drop down list
Author Message
Urgent help on range of drop down list

dear all,

I have encounterd this problem which i dont know how to
solve. The question is, suppose i have a searching page
which have 4 drop down list which content 2 for month and
2 year because i need to allow the user to select range of
month and year which mean that the user can select from
the drop down November 2001 to February 2002

I can read the month November and February as well as the
year 2001 and 2002 once the form post to another page, but
how do i read the value between the range of month which
mean i need to capture the value December 2001 and January
2002 to be able to list the results month by month

Do i make myself clear ?
need to help from u all, thanks

from,
Mae

Fri, 08 Oct 2004 17:14:11 GMT
Urgent help on range of drop down list
What do you mean by the "value" you need to capture between that range? Are
you referring to the number of days or months between those two dates? Maybe

Mario Vargas

Quote:
> dear all,

> I have encounterd this problem which i dont know how to
> solve. The question is, suppose i have a searching page
> which have 4 drop down list which content 2 for month and
> 2 year because i need to allow the user to select range of
> month and year which mean that the user can select from
> the drop down November 2001 to February 2002

> I can read the month November and February as well as the
> year 2001 and 2002 once the form post to another page, but
> how do i read the value between the range of month which
> mean i need to capture the value December 2001 and January
> 2002 to be able to list the results month by month

> Do i make myself clear ?
> need to help from u all, thanks

> from,
> Mae

Sat, 09 Oct 2004 03:58:56 GMT
Urgent help on range of drop down list
yes, what i meant was i wanted to know the number to
months between the two dates.

For example, if the user select "November 2001"
and "February 2002", I wanted to know the number in
between which mean i want to get November 2001, December
2001, January 2002 and February 2002 once the user submit
the form which selection "November 2001" and "February
2002"

How to do it ?

regards,
Mae

Quote:
>-----Original Message-----
>What do you mean by the "value" you need to capture

between that range? Are
Quote:
>you referring to the number of days or months between

those two dates? Maybe
Quote:

>Mario Vargas

>> dear all,

>> I have encounterd this problem which i dont know how to
>> solve. The question is, suppose i have a searching page
>> which have 4 drop down list which content 2 for month
and
>> 2 year because i need to allow the user to select range
of
>> month and year which mean that the user can select from
>> the drop down November 2001 to February 2002

>> I can read the month November and February as well as
the
>> year 2001 and 2002 once the form post to another page,
but
>> how do i read the value between the range of month which
>> mean i need to capture the value December 2001 and
January
>> 2002 to be able to list the results month by month

>> Do i make myself clear ?
>> need to help from u all, thanks

>> from,
>> Mae

>.

Sat, 09 Oct 2004 09:32:36 GMT
Urgent help on range of drop down list
You just start iterating from the start month until you reach December, and
when you reach December, you start the month out at January and increment
the year.  Every time you increment, first check against the end month/year.

year = startYear ;
month = startMonth ;
do {
/* whatever you want for each month */
month++ ;
if ( month > 12 ) {
month = 1 ;
year ++ ;
}

Quote:
} while ( year <= endYear && month <= endMonth ) ;

There may be a slick way using the Date object, but this is the
straightforward algorithm that works in most any language...

Grant

Quote:
> yes, what i meant was i wanted to know the number to
> months between the two dates.

> For example, if the user select "November 2001"
> and "February 2002", I wanted to know the number in
> between which mean i want to get November 2001, December
> 2001, January 2002 and February 2002 once the user submit
> the form which selection "November 2001" and "February
> 2002"

> How to do it ?

> regards,
> Mae

> >-----Original Message-----
> >What do you mean by the "value" you need to capture
> between that range? Are
> >you referring to the number of days or months between
> those two dates? Maybe

> >Mario Vargas

> >> dear all,

> >> I have encounterd this problem which i dont know how to
> >> solve. The question is, suppose i have a searching page
> >> which have 4 drop down list which content 2 for month
> and
> >> 2 year because i need to allow the user to select range
> of
> >> month and year which mean that the user can select from
> >> the drop down November 2001 to February 2002

> >> I can read the month November and February as well as
> the
> >> year 2001 and 2002 once the form post to another page,
> but
> >> how do i read the value between the range of month which
> >> mean i need to capture the value December 2001 and
> January
> >> 2002 to be able to list the results month by month

> >> Do i make myself clear ?
> >> need to help from u all, thanks

> >> from,
> >> Mae

> >.

Sat, 09 Oct 2004 15:14:31 GMT
Urgent help on range of drop down list
Actually, I should've used a simple while() loop to check that the start was
before the end (and BTW this was assuming a 1-based month index for
simplicity - if you're not using the month number to index another array):

while ( year <= endYear && month <= endMonth ) {
month++ ;
if ( month > 12 ) {
month = 1 ;
year ++ ;
}

Quote:
}

Quote:
> You just start iterating from the start month until you reach December,
and
> when you reach December, you start the month out at January and increment
> the year.  Every time you increment, first check against the end
month/year.

> year = startYear ;
> month = startMonth ;
> do {
>     /* whatever you want for each month */
>     month++ ;
>     if ( month > 12 ) {
>         month = 1 ;
>         year ++ ;
>     }
> } while ( year <= endYear && month <= endMonth ) ;

> There may be a slick way using the Date object, but this is the
> straightforward algorithm that works in most any language...

> Grant

> > yes, what i meant was i wanted to know the number to
> > months between the two dates.

> > For example, if the user select "November 2001"
> > and "February 2002", I wanted to know the number in
> > between which mean i want to get November 2001, December
> > 2001, January 2002 and February 2002 once the user submit
> > the form which selection "November 2001" and "February
> > 2002"

> > How to do it ?

> > regards,
> > Mae

> > >-----Original Message-----
> > >What do you mean by the "value" you need to capture
> > between that range? Are
> > >you referring to the number of days or months between
> > those two dates? Maybe

> > >Mario Vargas

> > >> dear all,

> > >> I have encounterd this problem which i dont know how to
> > >> solve. The question is, suppose i have a searching page
> > >> which have 4 drop down list which content 2 for month
> > and
> > >> 2 year because i need to allow the user to select range
> > of
> > >> month and year which mean that the user can select from
> > >> the drop down November 2001 to February 2002

> > >> I can read the month November and February as well as
> > the
> > >> year 2001 and 2002 once the form post to another page,
> > but
> > >> how do i read the value between the range of month which
> > >> mean i need to capture the value December 2001 and
> > January
> > >> 2002 to be able to list the results month by month

> > >> Do i make myself clear ?
> > >> need to help from u all, thanks

> > >> from,
> > >> Mae

> > >.

Sat, 09 Oct 2004 15:25:45 GMT
Urgent help on range of drop down list
Hi again,

I wrote the following methods. Please understand that this is a very quick
and dirty of solving the problem. It seems to work but I don't know up to
what extent because it needs further testing. At least it will be enough to
get you started with. I am afraid to add that although Grant's solution
seems very straight forward, it fails when I change the beginning date to
Nov 2000 and the stop date to Feb 2002. The result of the algorithm should
return 15 months, but it actually returns 11; that's because the month <=
endMonth condition fails when the while loop starts and because the initial
value of month is 11.

function daysToMonths( numDays )
{ // Converts a given value in days to months.

// Take the assumption that there are approximately 30 days in each
month.
// This will fail when the given number of days is less than 30.
return Math.floor( numDays / 30 );

Quote:
}

function millisecondsToDays( ms )
{
// There are 86,400,000 milliseconds in a day.
return ms / 8.64e7;

Quote:
}

function start()
{
var startDate = new Date( 2002, 0 );
var stopDate = new Date( 2003, 0 );
var daysBetween = millisecondsToDays( stopDate.getTime() -
startDate.getTime() );
var monthsBetween = daysToMonths( daysBetween );

Quote:
}

You would need to modify the daysToMonths() function so it correctly
calculates the numbers of months between a given date range. I am going to
try out a different way of doing this with the setTime() method of the Date
object.

Mario Vargas

Quote:
> yes, what i meant was i wanted to know the number to
> months between the two dates.

> For example, if the user select "November 2001"
> and "February 2002", I wanted to know the number in
> between which mean i want to get November 2001, December
> 2001, January 2002 and February 2002 once the user submit
> the form which selection "November 2001" and "February
> 2002"

> How to do it ?

> regards,
> Mae

> >-----Original Message-----
> >What do you mean by the "value" you need to capture
> between that range? Are
> >you referring to the number of days or months between
> those two dates? Maybe

> >Mario Vargas

> >> dear all,

> >> I have encounterd this problem which i dont know how to
> >> solve. The question is, suppose i have a searching page
> >> which have 4 drop down list which content 2 for month
> and
> >> 2 year because i need to allow the user to select range
> of
> >> month and year which mean that the user can select from
> >> the drop down November 2001 to February 2002

> >> I can read the month November and February as well as
> the
> >> year 2001 and 2002 once the form post to another page,
> but
> >> how do i read the value between the range of month which
> >> mean i need to capture the value December 2001 and
> January
> >> 2002 to be able to list the results month by month

> >> Do i make myself clear ?
> >> need to help from u all, thanks

> >> from,
> >> Mae

> >.

Sat, 09 Oct 2004 22:25:37 GMT
Urgent help on range of drop down list
I have one question for you? Are you developing for IE browsers only or for
many browsers, such as Netscape among others? I got the function that
correctly returns the number of months between any two dates, but I'm stuck
with the issue of browser compatibility. IE deals with the getYear() method
correctly and it constains the getFullYear() method of the Date object,
which returns the year as a four digit year. Let me know so I can post the
getMonthsInDateRange() function.

Mario Vargas

Quote:
> yes, what i meant was i wanted to know the number to
> months between the two dates.

> For example, if the user select "November 2001"
> and "February 2002", I wanted to know the number in
> between which mean i want to get November 2001, December
> 2001, January 2002 and February 2002 once the user submit
> the form which selection "November 2001" and "February
> 2002"

> How to do it ?

> regards,
> Mae

> >-----Original Message-----
> >What do you mean by the "value" you need to capture
> between that range? Are
> >you referring to the number of days or months between
> those two dates? Maybe

> >Mario Vargas

> >> dear all,

> >> I have encounterd this problem which i dont know how to
> >> solve. The question is, suppose i have a searching page
> >> which have 4 drop down list which content 2 for month
> and
> >> 2 year because i need to allow the user to select range
> of
> >> month and year which mean that the user can select from
> >> the drop down November 2001 to February 2002

> >> I can read the month November and February as well as
> the
> >> year 2001 and 2002 once the form post to another page,
> but
> >> how do i read the value between the range of month which
> >> mean i need to capture the value December 2001 and
> January
> >> 2002 to be able to list the results month by month

> >> Do i make myself clear ?
> >> need to help from u all, thanks

> >> from,
> >> Mae

> >.

Sun, 10 Oct 2004 00:22:52 GMT
Urgent help on range of drop down list

at Tue, 23 Apr 2002 10:25:37 :-

OP wants the number of months "between" two dates ...

Quote:
>function millisecondsToDays( ms )
>{
>   // There are 86,400,000 milliseconds in a day.
>   return ms / 8.64e7;
>}

In many countries, only for about 363/365 of the days.  Never do civil
date arithmetic with time.

Quote:
>function start()
>{
>   var startDate = new Date( 2002, 0 );
>   var stopDate = new Date( 2003, 0 );
>   var daysBetween = millisecondsToDays( stopDate.getTime() -
>startDate.getTime() );
>   var monthsBetween = daysToMonths( daysBetween );

If you know the initial and final dates, as YI MI DI & YF MF DF, then
all you need to do for the number of months is
YF*12+MF - YI*12+MI
"between", and possibly subtracting one if DF < / <= DI.

--

Web  <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS, EXE in  <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm  &c.

Sun, 10 Oct 2004 04:05:46 GMT
Urgent help on range of drop down list
I don't know if you're checking back on my response, but what do you mean by

BTW, I like your solution. That is the equation I was looking for but was
unable to derive. I knew it had to be a conversion issue. Anyway, I think I
made it very clear when I said that it was a "very quick and dirty way of
solving the problem," no? Moreover, my initial solution doesn't work for all
cases.

Thanks, Doc.

Quote:

> at Tue, 23 Apr 2002 10:25:37 :-

> OP wants the number of months "between" two dates ...

> >function millisecondsToDays( ms )
> >{
> >   // There are 86,400,000 milliseconds in a day.
> >   return ms / 8.64e7;
> >}

> In many countries, only for about 363/365 of the days.  Never do civil
> date arithmetic with time.

> >function start()
> >{
> >   var startDate = new Date( 2002, 0 );
> >   var stopDate = new Date( 2003, 0 );
> >   var daysBetween = millisecondsToDays( stopDate.getTime() -
> >startDate.getTime() );
> >   var monthsBetween = daysToMonths( daysBetween );

> If you know the initial and final dates, as YI MI DI & YF MF DF, then
> all you need to do for the number of months is
>         YF*12+MF - YI*12+MI
> "between", and possibly subtracting one if DF < / <= DI.

> --

MIME. ?
>  Web  <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links,
acronyms
>  PAS, EXE in  <URL:http://www.merlyn.demon.co.uk/programs/> - see
00index.txt.
>  Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm

&c.

Tue, 12 Oct 2004 05:25:29 GMT
Urgent help on range of drop down list
Apparently Dr Stockton would like us all to stop blindly pressing 'reply' in
our email clients and thus including the entire thread in the post that we
submit - seems that he may be on the end of a 56K dial-up.

Sounds fair enough though if explained in plain English.

Another favourite phrase that has been used by Dr Stockton (and confused
absolutely everybody concerned) was 'eschew surplus usage' - I still can't
remember what it meant in the end [grin].

Chris Barber.

Mmmm.- must remember to delete some of the stuff below this ....

at Tue, 23 Apr 2002 10:25:37 :-

... some text ...

--

MIME. ?
Web  <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links,
acronyms
PAS, EXE in  <URL:http://www.merlyn.demon.co.uk/programs/> - see
00index.txt.
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm
&c.

Tue, 12 Oct 2004 06:56:18 GMT

 Page 1 of 1 [ 10 post ]

Relevant Pages