mcal_day_of_week

(PHP 3 >= 3.0.13, PHP 4, PECL)

mcal_day_of_week --  Returns the day of the week of the given date

Description

int mcal_day_of_week ( int year, int month, int day )

mcal_day_of_week() returns the day of the week of the given date. Possible return values range from 0 for Sunday through 6 for Saturday.


add a note add a note User Contributed Notes
ssimon at latinschool dot org
05-Aug-2003 11:29
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

?>
mail at azov dot info
30-Jul-2003 08:17
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;
};
cigalcohol at yahoo dot com
11-Aug-2002 05:35
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";

?>
dagjo at stud dot ntnu dot no
04-Jun-2001 02:57
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

?>