list of days between two days

R

RobG

kirke said:
Hi. I want to make a list of days between two days.
How can I make it???
Thx.

Try:

<script type="text/javascript">
function showDays(f){
var selS = f.startDay;
var selE = f.endDay;
var days = [];
var i = 0;
while (i<7 && !selS.options.selected){
i++;
}
while (!selE.options.selected){
days.push(selE.options[i++].text);
i = i%7;
}
days.push(selE.options.text);
f.dayList.value = days.join('\n');
}
</script>
<form action="">
<div>
<label for="startDay">Start day:
<select name="startDay">
<option value="0" selected>Monday
<option value="1">Tuesday
<option value="2">Wednesday
<option value="3">Thursday
<option value="4">Friday
<option value="5">Saturday
<option value="6">Sunday
</select></label>
<label for="endDay">End day:
<select name="endDay">
<option value="0">Monday
<option value="1">Tuesday
<option value="2">Wednesday
<option value="3">Thursday
<option value="4">Friday
<option value="5">Saturday
<option value="6" selected>Sunday
</select></label>
<input type="button" value="Show day list"
onclick="showDays(this.form);">
<br>
<textarea readonly name="dayList" cols=10
rows=8></textarea>
</div>
</form>
 
K

kirke

Wow. yours are great.
However, I took a mistake. I mean date not day.SORRY.
Thus, start date is 10/19/2006 and end date is 10/31/2006 Then.
I want to make a list of 10/19/2006, 10/20/2006,....,10/30/2006,
10/31/2006 like this.

kirke said:
Hi. I want to make a list of days between two days.
How can I make it???
Thx.

Try:

<script type="text/javascript">
function showDays(f){
var selS = f.startDay;
var selE = f.endDay;
var days = [];
var i = 0;
while (i<7 && !selS.options.selected){
i++;
}
while (!selE.options.selected){
days.push(selE.options[i++].text);
i = i%7;
}
days.push(selE.options.text);
f.dayList.value = days.join('\n');
}
</script>
<form action="">
<div>
<label for="startDay">Start day:
<select name="startDay">
<option value="0" selected>Monday
<option value="1">Tuesday
<option value="2">Wednesday
<option value="3">Thursday
<option value="4">Friday
<option value="5">Saturday
<option value="6">Sunday
</select></label>
<label for="endDay">End day:
<select name="endDay">
<option value="0">Monday
<option value="1">Tuesday
<option value="2">Wednesday
<option value="3">Thursday
<option value="4">Friday
<option value="5">Saturday
<option value="6" selected>Sunday
</select></label>
<input type="button" value="Show day list"
onclick="showDays(this.form);">
<br>
<textarea readonly name="dayList" cols=10
rows=8></textarea>
</div>
</form>
 
J

Julian Turner

kirke said:
Wow. yours are great.
However, I took a mistake. I mean date not day.SORRY.
Thus, start date is 10/19/2006 and end date is 10/31/2006 Then.
I want to make a list of 10/19/2006, 10/20/2006,....,10/30/2006,
10/31/2006 like this.

Try the Date object.

I.e.

var d = new Date(2006,9,19);
var d2 = new Date(2006,10,31);
var aDates = [];

do
{
aDates.push(d.toString());
d.setDate(d.getDate()+1);
}
while (d <= d2);

alert(aDates.join("\r\n"));

Regards

Julian
 
R

RobG

kirke said:
Wow. yours are great.

Please do not top post here, reply below trimmed quotes of what you are
replying to.
However, I took a mistake. I mean date not day.SORRY.
Thus, start date is 10/19/2006 and end date is 10/31/2006 Then.
I want to make a list of 10/19/2006, 10/20/2006,....,10/30/2006,
10/31/2006 like this.

And your attempt at this looks like... ? The date format you have
shown will likely be misunderstood by the vast majority of web users,
it is peculiar to only one country that I know of.

As a hint, get a date from some input elements. Validate the format
and that they generate a valid date, then use them to create new date
objects. Add one to the start date until you reach the end date,
collecting the dates along the way. Then write the list of dates
you've generated to some element - maybe a text area, span or p
element.

The script I posted gives you a start, but you will have to make
significant changes.

There are some date routines here:

<URL: http://www.merlyn.demon.co.uk/js-dates.htm >
 
E

Evertjan.

Julian Turner wrote on 19 okt 2006 in comp.lang.javascript:
Wow. yours are great.
However, I took a mistake. I mean date not day.SORRY.
Thus, start date is 10/19/2006 and end date is 10/31/2006 Then.
I want to make a list of 10/19/2006, 10/20/2006,....,10/30/2006,
10/31/2006 like this.

Try the Date object.

I.e.

var d = new Date(2006,9,19);
var d2 = new Date(2006,10,31);
var aDates = [];

do
{
aDates.push(d.toString());
d.setDate(d.getDate()+1);
}
while (d <= d2);

alert(aDates.join("\r\n"));

Good plan.
To keep up with the OQ, without using the localized version:

<script type='text/javascript'>

var d = new Date(2006,9,19);
var d2 = new Date(2006,10,31);

while (d <= d2) {
document.write(d.getYear() +
'/' + T(d.getMonth()+1) +
'/' + T(d.getDate()) + '<br>');
d.setDate(1 + d.getDate());
};

function T(x){
return (x < 10) ? "0" + x : x;
};

</script>
 
J

J R Stockton

Thu said:
To keep up with the OQ, without using the localized version:

<script type='text/javascript'>

var d = new Date(2006,9,19);


var d = new Date("2006/10/19");

is localised internationally, albeit with a non-ISO separator; it avoids
that irritating error of 1 in the month, which is liable to lead to
human error.


As well as the OP not having defined "day", he or she did not indicate
whether "between" means "between" or is intended to be inclusive.
Selection of while-do or do-while loop and of terminal condition should
fix that.

If the dates are supplied as Y M D numbers, rather than in an existing
Object, working in UTC would be faster.

If the dates are supplied as Objects, one must consider whether they may
have non-zero time components, and whether that matters.
 
J

Julian Turner

J R Stockton wrote:

[snip]
As well as the OP not having defined "day", he or she did not indicate
whether "between" means "between" or is intended to be inclusive.
Selection of while-do or do-while loop and of terminal condition should
fix that.

[snip]


The OP gave an example (in a second message):

"Thus, start date is 10/19/2006 and end date is 10/31/2006 Then.
I want to make a list of 10/19/2006, 10/20/2006,....,10/30/2006,
10/31/2006 like this. "

Regards

Julian Turner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top