Jump to content

[SOLVED] Day of the Week Program


sgalatas

Recommended Posts

Good Evening,  I am trying to write a program that will give me the day of the week without using the date function.  I input the date and it's supposed to spit out the name of the day of the week.  Here is what I have so far.  I don't know quite what to do next.

 

???

<html>

<head>

<title>Day of the Week</title>

</head>

<body>

<h1 style="text-align: center; color: navy" >Day of the Week Calculator</h1>

<form action="wages.php" method="get">

<fieldset>

<label for="mm">Enter Date (mm/dd/yyyy)</label>

<input type= "text" name= "mm"  id="mm" size="2">

</input>

<input type="text" name="dd" id="dd" size="2">

</input>

<input type="yyyy" name="yyyy" id="yyyy" size="4">

</input>

 

</fieldset>

<!

<fieldset>

<input type= "submit" name= "submit" id="submit" value= "Enter">

</input>

<input type="reset" name="reset" value="Cancel">

</input>

</fieldset>

 

</form>

 

 

<?php

 

// Day of the Week Program

 

$mm=$_GET['mm'];

$dd=$_GET['dd'];

$yyyy=$_GET['yyyy'];

 

$ddtring=array(Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday);

$mmstring=array('31','','31','30','31','30','31','31','30','31','30','31');

 

 

 

 

 

?>

 

 

 

 
Link to comment
https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/
Share on other sites

It's an assignment that I have and the instructor said that we could not use the date function.  I have revised the program.  But I still can not get it to run.

 

<html>

<!-- Homework 3 -->

<head>

<title>Day of the Week</title>

</head>

<body>

<h1 style="text-align: center; color: navy" >Day of the Week Calculator</h1>

<form action="wages.php" method="get">

<fieldset>

<label for="mm">Enter Date (mm/dd/yyyy)</label>

<input type= "text" name= "mm"  id="mm" size="2">

</input>

<input type="text" name="dd" id="dd" size="2">

</input>

<input type="yyyy" name="yyyy" id="yyyy" size="4">

</input>

 

</fieldset>

<!

<fieldset>

<input type= "submit" name= "submit" id="submit" value= "Enter">

</input>

<input type="reset" name="reset" value="Cancel">

</input>

</fieldset>

 

</form>

 

 

<?php

 

 

 

 

//Homework 3 - Day of the Week Program

 

$mm = $_GET[mm];

$dd = $_GET[dd];

$yyyy = $_GET[yyyy];

 

$ddstring = array(Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday);

$mmstring = array('31','','31','30','31','30','31','31','30','31','30','31');

$daynumberarray = ('31','59','90','120','151','181','217','243','273','304','334','365');

$daynumberarrayleap = ('31','60','91','121','152','182','218','244','274','305','335','366');

 

if ($yyyy % 4 == 0){

  $leapyear = true;

}else{

  $leapyear = false;

}

if (leapyear == true){

  $mmstring[1] = 29;

}else{

  $mmstring[1] = 28;

if (($mm < 1) || ($mm > 12) || ($dd < 1) || ($dd > $mmstring[$mm - 1]) || ($yyyy < o)){

  echo "invalid data";

}

$daynumber = ($yyyy - 1900) * 365 + ($yyyy - 1900)/4 + $dd;

if ($mm > 1){

  if ($leapyear == true){

    $daynumber = $daynumber + $daynumberarrayleap[$mm - 2];

}else{

  $daynumber = $daynumber + $daynumberarray[$mm - 2];

}

}

 

$result = $daynumber % 7

 

switch($result){

  case '0':

  echo "The day of the week is Sunday";

  break;

  case '1':

  echo "The day of the week is Monday";

  break;

  case '2':

  echo "The day of the week is Tuesday";

  break;

  case '3':

  echo "The day of the week is Wednesday";

  break;

  case '4':

  echo "The day of the week is Thursday";

  break;

  case '5':

  echo "The day of the week is Friday";

  break;

  case '6':

  echo "The day of the week is Saturday";

break;

default:

echo "something went horribly wrong...";

break;

}

 

?>

</body>

</html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

</body>

</html>

 

 

 

 

Based on my first post (reply #3)

<?php
$days = array ('Thursday','Friday','Saturday','Sunday','Monday','Tuesday','Wednesday');
$date = '2007-11-29';
$dt = strtotime($date);
$to_days = floor($dt/86400);
$dow = $days[$to_days % 7];

echo $dow;           // Thursday
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.