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
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>

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.