473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

First & Third Wednesday of each month

I need to document.write out a select list populated with the dates for the
first and third Wednesday of each month. How do I get to the actual days?
<select name="mySelect">
<option value="Oct 1, 2003">Oct 1, 2003</option>
<option value="Oct 15, 2003">Oct 15, 2003</option>
.....and so on for a continual 12 month period
</select>

Thanks,

John
Jul 20 '05 #1
3 9549
Lee
johkar said:

I need to document.write out a select list populated with the dates for the
first and third Wednesday of each month. How do I get to the actual days?
<select name="mySelect">
<option value="Oct 1, 2003">Oct 1, 2003</option>
<option value="Oct 15, 2003">Oct 15, 2003</option>
....and so on for a continual 12 month period
</select>


In Javascript, the days of the week are represented by
the numbers 0-6, where 6="Sunday".
Given "firstDay" as the numerical day of the week of the
first day of the month, you can calculate the date of the
first Wednesday (3="Wednesday") as:
1+(3-firstDay+7)%7;
and the third Wednesday is 14 days later.
<html>
<body>
<form>
<script type="text/javascript">
var mName=["January","February","March","April","May","June", "July",
"August","September","October","November","Decembe r"];
var now=new Date();
now.setDate(1);
var month=now.getMonth();
var year=now.getFullYear();
var html="<select name=\"mySelect\">\n";
for(var i=0;i<12;i++){
// now is a Date object representing the first day
// of month "month" of year "year".
var firstDay=now.getDay();
var firstWed=1+(3-firstDay+7)%7;
var thirdWed=firstWed+14;
var monthName=mName[now.getMonth()];
html+="<option>"+monthName+" "+firstWed+", "+year+"</option>\n";
html+="<option>"+monthName+" "+thirdWed+", "+year+"</option>\n";
month++;
if(month==12){
month=0;
year++;
}
now=new Date(year,month,1);
}
html+="</select>\n";
document.write(html);
</script>
</form>
</body>
</html>

Jul 20 '05 #2
JRS: In article <5k*****************@newsread4.news.pas.earthlink. net>,
seen in news:comp.lang.javascript, johkar <no********@link.net> posted
at Sat, 11 Oct 2003 13:11:29 :-
I need to document.write out a select list populated with the dates for the
first and third Wednesday of each month. How do I get to the actual days?
<select name="mySelect">
<option value="Oct 1, 2003">Oct 1, 2003</option>
<option value="Oct 15, 2003">Oct 15, 2003</option>
....and so on for a continual 12 month period
</select>


After you have established the first Wednesday of a suitable month, by
such means as
with (d = new Date(YYYY,MM-1,1)) setDate(((10-getDay())%7)+1)
then add 14 days for the third Wednesday.
with (d = new Date(YYYY,MM-1,1)) setDate(T=((10-getDay())%7)+1)
// ...
d.setDate(T+14)
You can then either repeat for each month in turn[1], or add a further
14 or 21 days and see, after that, whether you need to add or subtract
7. The test can be on whether the month has changed, or on comparison
of the date with, say, 15.

d.setDate(T+35), for example, will change the month properly,

[1] to get to the next month, it is only necessary to increment MM.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #3
Thanks to you both, I was trying to make it harder than that. ;-)

John

"johkar" <no********@link.net> wrote in message
news:5k*****************@newsread4.news.pas.earthl ink.net...
I need to document.write out a select list populated with the dates for the first and third Wednesday of each month. How do I get to the actual days?
<select name="mySelect">
<option value="Oct 1, 2003">Oct 1, 2003</option>
<option value="Oct 15, 2003">Oct 15, 2003</option>
....and so on for a continual 12 month period
</select>

Thanks,

John

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mark Anthony | last post by:
ok so first i will give write the question out, my code, the db structure, then what is going wrong. Write a report to return the top store in terms of Sales Dollars for each month sales have...
1
by: amit.gaind | last post by:
Please suggest something to get date corresponding to 2nd wednesday of each month in VB.NET.
3
by: amit.gaind | last post by:
Please suggest how to get date correponding to 2nd wednesday of each month ?
4
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
3
by: ats | last post by:
Does anybody have any sample code for calculating the date for teh last Friday in each month. TIA -- ats@jbex When an old lady got hit by a truck I saw the wicked gleam in your eyes
2
by: p655279 | last post by:
Dear All, Does anyone know how to extract first business date of each month in a DB2 SQL? many many thanks
12
Microblitz
by: Microblitz | last post by:
Graph of top four products each month for last 6 months? (Yeah I know I typ'od the title) I need create a chart which displays the four highest selling products for each month in the last 6...
3
by: Gurunath Dhage | last post by:
Need help on access database design and queries Hi All, I’m working on a small project for loan Financial service company. I’m developing a Schedule Entry System . It has a Leasee who takes the...
2
by: bnashenas1984 | last post by:
Hi everyone I'm building an Ecommerce website with PHP and MYSQL. What I need to do is to categorize orders for each month or year to show a statistic table The DB table looks like this : ID :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.