grr it's furstrating me
Date function, finding the day on which a month begins
Moderator: General Moderators
-
VirtualEnder
- Forum Newbie
- Posts: 3
- Joined: Mon Jun 16, 2003 9:12 am
Date function, finding the day on which a month begins
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
thanks ahead of time for any suggestions.
grr it's furstrating me
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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
Mac
-
VirtualEnder
- Forum Newbie
- Posts: 3
- Joined: Mon Jun 16, 2003 9:12 am
Thanks guys I figured it out, here's my code
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
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;
}
}-
VirtualEnder
- Forum Newbie
- Posts: 3
- Joined: Mon Jun 16, 2003 9:12 am
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
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;
}