# Find the first day of the month

**URL:** https://forum.kirupa.com/t/find-the-first-day-of-the-month/66362
**Category:** flash
**Created:** [October 5, 2004, 8:35am UTC](https://forum.kirupa.com/t/find-the-first-day-of-the-month/66362 "2004-10-05T08:35:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Phat7](https://avatars.discourse-cdn.com/v4/letter/p/6de8d8/32.png) [@Phat7](https://forum.kirupa.com/u/Phat7)
#### Post date: [October 5, 2004, 8:35am UTC](https://forum.kirupa.com/t/find-the-first-day-of-the-month/66362/1 "2004-10-05T08:35:10Z")

</div>

This goes out to all the AS gurus 😛

How would you find what weekday is the first day of the month? I’m doing a calendar similar to the component included in MX2004. Currently I’m working on this code:

```auto
// DEFINE ARRAY GETINDEX PROTOTYPE
Array.prototype.getIndex = function(data) {
	for (i=0; i<this.length; ++i) {
		if (this* == data) {
			return i;
		}
	}
	return -1;
};
// END

// DEFINE ARRAYS
months = new Array("JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER");
daysInMonths = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
weekdays = new Array("Mo", "Tu", "We", "Th", "Fr", "Sa", "Su");
// END

// DEFINE DATE OBJECT AND CURRENT DATE
now = new Date();
selectedMonth = now.getMonth();
today = now.getDate();
// END

// MOVE SUNDAY TO THE END OF ARRAY
weekday = weekdays[now.getDay()-1];
if (weekday == undefined) {
	weekday = weekdays[6];
}
// END

// FIND THE FIRST DAY OF THE MONTH
weekdayNum = weekdays.getIndex(weekday);
firstweekdayNum = weekdays.getIndex(weekday);
daysinmonth = daysInMonths[selectedMonth];
for (k=now.getDate(); k>1; k--) {
	if (firstweekdayNum == -1) {
		firstweekdayNum = 6;
	}
	firstweekdayNum -= 1;
}
// END

```

This code is working alright. But what if I want to find the first day of the last month? Or the next month?..
