Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old February 8th, 2008, 07:04 PM
markoc's Avatar
markoc markoc is offline
Contributing User
ASP Free Regular (2000 - 2499 posts)
 
Join Date: Nov 2003
Location: UK
Posts: 2,088 markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 23 h 55 m 52 sec
Reputation Power: 172
JavaScript - Javascript function to get each monday in month

here is one way to get each monday in the current month.
please note this is for UK hense the UTC dates.

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Get each monday in the current month</title>
<script language="javascript">
<!--//

// currentDateStart is the 1st of the current month
var currentDateStart = new Date;
currentDateStart.setDate(1);
currentDateStart.getUTCMonth();
var m = currentDateStart.getUTCMonth();
currentDateStart.getUTCFullYear();
var y = currentDateStart.getUTCFullYear();

// currentDateEnd is the 1st of the next month
var currentDateEnd = new Date;
currentDateEnd.setDate(1);
var endMonth = currentDateStart.getUTCMonth();
var endYear = currentDateStart.getUTCFullYear();
if (endMonth < 10) {
	endMonth += 1;
}
else {
	endMonth = 1;
	endYear += 1;
}
currentDateEnd.setMonth(endMonth);
currentDateEnd.setFullYear(endYear);
// once you have the 1st of next month you need to subtract one day
// to get the date of the last day of the current month you need to
// subtract 86400000 milliseconds which is the value for one day
// this will save time leap years ect.
var endDate = new Date( currentDateEnd.getTime() - 86400000 );
var endDateDay = endDate.getDate();

// this function loops through each day and finds the mondays
// and places them in to an array
var mondayArray = new Array();
var c = 0;
function getMondayArray() {
	var loopDate = new Date;
	var dayName;
	var lDay;
	var lMonth;
	for (var d=1;d<=endDateDay;d++) {
		loopDate.setDate(d);
		loopDate.setMonth(m);
		loopDate.setFullYear(y);
		dayName = loopDate.getDay();
		// the getDay value for monday is 1
		if (dayName == 1) {
			c += 1;
			lDay = loopDate.getDate();
			if (lDay < 10) lDay = "0" + lDay;
			lMonth = (loopDate.getMonth() + 1)
			if (lMonth < 10) lMonth = "0" + lMonth;
			mondayArray[c] = (lDay + "-" + lMonth + "-" + loopDate.getFullYear());
		}
	}
}

// this function collects the data and displays it on the page
function displayResults() {
	var headerSpan = "";
	var resultsSpan = "";
	var sDay = currentDateStart.getDate();
	if (sDay < 10) sDay = "0" + sDay;
	var sMonth = (currentDateStart.getMonth() + 1);
	if (sMonth < 10) sMonth = "0" + sMonth;
	headerSpan += ("<h2>Date Range: 01" + "-" + sMonth + "-" + currentDateStart.getFullYear() + " to ");
	var eMonth = (endDate.getMonth() + 1);
	if (eMonth < 10) eMonth = "0" + eMonth;
	headerSpan += (endDate.getDate() + "-" + eMonth + "-" + endDate.getFullYear() + "</h2>");
	
	resultsSpan += ("<b>RESULTS: " + c + "</b>");
	for (var r=1;r<=c;r++) {
		resultsSpan += ("<br />" + mondayArray[r]);
	}
	
	document.getElementById("headerSpan").innerHTML = headerSpan;
	document.getElementById("resultsSpan").innerHTML = resultsSpan;
}

function show_dates() {
	getMondayArray();
	displayResults();
}
//-->
</script>
</head>
<body>
<a href="javascript:show_dates();">show date results</a>
<p>&nbsp;</p>
<span id="headerSpan"></span>
<span id="resultsSpan"></span>
</body>
</html>
__________________
Hope this advise helps.

If so please show your appreciation by adding reputation points (clcik gauge image on top right of this post).

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > JavaScript - Javascript function to get each monday in month


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway