Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : MCAL Functions : mcal_day_of_week

mcal_day_of_week

Returns the day of the week of the given date (PHP 4)
int mcal_day_of_week ( int year, int month, int day )


Related Examples ( Source code ) » mcal_day_of_week


Code Examples / Notes » mcal_day_of_week

dagjo

It is quite straightforward... Here's an example:
<?php
$year = strftime('%Y');
$month = strftime('%m');
$day = strftime('%d');
$weekDay = mcal_day_of_week($year, $month, $day);
switch ($weekDay) {
case 0:
print("Today is Sunday");
break;
case 1:
print("Today is Monday");
break;
   
...
   
case 6:
print("Today is Saturday");
break;
} // end switch
?>


ssimon

If you don't have mcal, and need a replacement, here is an even easier way:
<?php
$utime = mktime (1,1,1,$month,$day,$year);
$weekday=date('w',$utime);   //  0 for Sunday through 6 for Saturday, just like mcal_day_of_week
?>


cigalcohol

I don't have the MCAL lib, so I wrote a script that will return the day of the week for any date 2000+ using Zeller's Rule:
http://mathforum.org/dr.math/faq/faq.calendar.html
I only needed it to work for this century, so I replaced a few variables with constants, and I split up the equation itself into its component parts because I'm something of a n00b and I get condused easily.
$y needs to be two digits, not four, eg, "02", "13", vs 2002, 2013, &c.
<?
if ( $m >= "3") {
    $mn = $m - 2; }
else {
    $mn = $m + 10; }
if ( $mn >= "11" ) {
    $yn = $y - 1; }
else { $yn = $y; }
$rem = $d;
$rem =  floor((13*$mn-1)/5) + $rem;
$rem = $rem + $yn;
$rem = floor($yn/4) + $rem;
$rem = $rem  - 35;
$rem = $rem % 7;
if ($rem < 0) {
    $rem = $rem + 7;}
if ($rem == "0") { $w = "Sun"; }
elseif ($rem == "1") { $w = "Mon"; }
elseif ($rem == "2") { $w = "Tue"; }
elseif ($rem == "3") { $w = "Wed"; }
elseif ($rem == "4") { $w = "Thu"; }
elseif ($rem == "5") { $w = "Fri"; }
elseif ($rem == "6") { $w = "Sat"; }
echo "$m.$d.$y is a $w";
?>


mail

I did it much easier (without "mcal" library):
function convertday($n){
switch ($n){
case "Mon": return "Monday";break;
case "Tue": return "Tuesday";break;
case "Wed": return "Wednesday";break;
case "Thu": return "Thursday";break;
case "Fri": return "Friday";break;
case "Sat": return "Saturday";break;
case "Sun": return "Sunday";break;
};
};
function curdate(){
$ret=date("d-m-Y").", ".convertday(date("D"));
return $ret;
};


Change Language


Follow Navioo On Twitter
mcal_append_event
mcal_close
mcal_create_calendar
mcal_date_compare
mcal_date_valid
mcal_day_of_week
mcal_day_of_year
mcal_days_in_month
mcal_delete_calendar
mcal_delete_event
mcal_event_add_attribute
mcal_event_init
mcal_event_set_alarm
mcal_event_set_category
mcal_event_set_class
mcal_event_set_description
mcal_event_set_end
mcal_event_set_recur_daily
mcal_event_set_recur_monthly_mday
mcal_event_set_recur_monthly_wday
mcal_event_set_recur_none
mcal_event_set_recur_weekly
mcal_event_set_recur_yearly
mcal_event_set_start
mcal_event_set_title
mcal_expunge
mcal_fetch_current_stream_event
mcal_fetch_event
mcal_is_leap_year
mcal_list_alarms
mcal_list_events
mcal_next_recurrence
mcal_open
mcal_popen
mcal_rename_calendar
mcal_reopen
mcal_snooze
mcal_store_event
mcal_time_valid
mcal_week_of_year
eXTReMe Tracker