Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2004, 09:10 AM
Authorized User
 
Join Date: Sep 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default creating dates into the future

using the following code to build a list of Tuesdays for the current year. Script starts to error after the 5th iteration. If I use any of the counter numbers instead of the var counter the script will find the appropriate day. With the var counter I have errors. Displaying the var counter to detect any errors.

<html>
<body>
<script>
var meetingDate = new Date("1 Jan 2004");



var counter = 6;


while (counter < 366 )
{
meetingDate.setDate(counter);
var dateNow = meetingDate.getDate();
var monthNow = meetingDate.getMonth() + 1;
var yearNow = meetingDate.getFullYear();

document.write("Tuesday " + monthNow + "/" + dateNow + "/" + yearNow + "-" + " counter is " + counter + "<br>");
counter = counter + 7;
}
</script>
</body>
</html>

 
Old May 27th, 2004, 04:26 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

the script is working very will getting all tuesdays in the year
what is the error appeared to you

Ahmed Ali
Software Developer
 
Old May 28th, 2004, 10:38 AM
Authorized User
 
Join Date: Sep 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

note the output fron week 5 on. this is where the problems start

Tuesday 1/6/2004- counter is 6
Tuesday 1/13/2004- counter is 13
Tuesday 1/20/2004- counter is 20
Tuesday 1/27/2004- counter is 27
Tuesday 2/3/2004- counter is 34
Tuesday 3/12/2004- counter is 41
Tuesday 4/17/2004- counter is 48
Tuesday 5/25/2004- counter is 55
Tuesday 7/1/2004- counter is 62
Tuesday 9/7/2004- counter is 69
Tuesday 11/15/2004- counter is 76
Tuesday 1/22/2005- counter is 83
Tuesday 3/31/2005- counter is 90
Tuesday 6/5/2005- counter is 97
Tuesday 9/12/2005- counter is 104
Tuesday 12/20/2005- counter is 111
Tuesday 3/28/2006- counter is 118
Tuesday 7/3/2006- counter is 125
Tuesday 11/9/2006- counter is 132
Tuesday 3/19/2007- counter is 139
Tuesday 7/24/2007- counter is 146
Tuesday 11/30/2007- counter is 153
Tuesday 4/8/2008- counter is 160


 
Old May 28th, 2004, 10:53 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try declaring a new date every time.

Add this line right before the setDate line:

meetingDate = new Date();

HTH,

Snib

<><





Similar Threads
Thread Thread Starter Forum Replies Last Post
future of XML bcogney XML 1 April 19th, 2006 04:48 AM
the future of p2p gwier Intro Programming 0 April 13th, 2006 01:51 AM
VB6 future jagguy Pro VB 6 0 December 17th, 2004 09:06 PM
ASP future alitoday Classic ASP Databases 5 August 26th, 2004 10:43 PM
The Future of Web Services Jonny .NET Web Services 1 October 15th, 2003 09:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.