Page 1 of 1

Date function, finding the day on which a month begins

Posted: Mon Jun 16, 2003 9:12 am
by VirtualEnder
Ok, here's the deal, I'm writing a script for a calendar program I have in flash that reads a specific file format to retrieve its information. I'm trying to make a wizard type interface for administration to generate the file in the right form. I have almost everything done, but this one thing is really bugging me. I want to generate a graphical callendar once you have selected the month. I'm haveing trouble finding a way to figure out wich day of the week the month starts on. Any recomendations on how to find that? I was thinking I could generate a timestamp based on the month they selected in the previous step, and return the day. All I need to know is "how many days past sunday is the first day of month?" I have the rest written.

grr it's furstrating me :x thanks ahead of time for any suggestions.

Posted: Mon Jun 16, 2003 10:12 am
by twigletmac
If you get a timestamp for the first day of the month then you can use the date() function to find out which day of the week that is.

Mac

Posted: Mon Jun 16, 2003 10:44 am
by VirtualEnder
Thanks guys I figured it out, here's my code

Code: Select all

function offset( $month , $year ) {
	// This function returns the number of days past sunday the month begins
	$date = getdate(mktime(0,0,0,$month,1,$year,-1);
	$day = $date['weekday'];
	if ( $day == 'Sunday' ) {
		return 0;
	}
	if ( $day == 'Monday' ) {
		return 1;
	}
	if ( $day == 'Tuesday' ) {
		return 2;
	}
	if ( $day == 'Wednessday' ) {
		return 3;
	}
	if ( $day == 'Thursday' ) {
		return 4;
	}
	if ( $day == 'Friday' ) {
		return 5;
	}
	if ( $day == 'Saturday' ) {
		return 6;
	}
}
I haven't tested it yet, I don't have acess to my server right now (internet connection is down where my test server is) but I think it will work

Posted: Mon Jun 16, 2003 2:18 pm
by VirtualEnder
Ok I found an even easier way to do this. I should have done it first! But hey i've only known php for less than a week, so I'm not too disappointed in myself :lol:

Code: Select all

function offset( $month , $year ) {
	// This function returns the number of days past sunday the month begins
	$date = mktime(0,0,0,$month,1,$year,-1);
	$day = strftime( "%u", $date);
	return $day;
}