In this article I would like to share with you a sample program in PHP that I wrote that will determine or check what is the day in a given date by our user using PHP as programming language I called this program Date Checker. What our program will do is very simple it will ask the user to enter the month, day and year and then our program will determine what day will fall in the given date by our user. I also added a function that will ask the user if the user want to continue using the program or not. I hope you will find my work useful in your programming assignments and projects.
If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com. People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360.
Program Listing
<html>
<head>
<title>Day Checker</title>
<head>
<style>
body {
font-size:25px;
font-family:arial;
color:blue;
}
#banner {
width: 750px;
background-color: yellow;
height: 100px;
margin: 0 auto;
position: inherit;
top: 100;
left: 0;
bottom:0;
right: 0;
padding: 16px 16px;
border-radius: 75px;
border: 5px solid #fba827;
}
/* BUTTONS */
#submit {
background: #0a7d66;
background-image: -moz-linear-gradient(#0fb493, #0a7d66);
background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, #6cbb6b),color-stop(1, #0fb493));
margin: 0 0 0 2px;
padding: 15px 20px;
border-radius: 3px 70px 70px 3px;
-moz-border-radius: 3px 70px 70px 3px;
border-color: #0fb493 #0da284 #0c9075;
-moz-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
-webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
font: 16px 'Droid Serif', serif;
background: #0fb493;
color: blue;
cursor: pointer;
text-shadow: 0 5px 0 rgba(255,255,255,0.4);
}
#submit:hover {
background-color: #0fb493;
background-image: linear-gradient(#0a7d66, #0fb493);
}
#submit:active {
background: #0fb493;
outline: none;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
}
#submit::-moz-focus-inner {
border: 0; /* Small centering fix for Firefox */
}
.inputs {
-webkit-border-radius: 20px 3px 3px 20px;
-moz-border-radius: 20px 3px 3px 20px;
-ms-border-radius: 20px 3px 3px 20px;
-o-border-radius: 20px 3px 3px 20px;
border-radius: 20px 3px 3px 20px;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
background: yellow;
border: 5px solid #fba827;
color: blue;
font: 22px 'Droid Serif', serif;
margin: 0 0 10px;
padding: 15px 20px 15px 20px;
width: 150px;
}
</style>
<?php
$month = $_POST['mon'];
$day = $_POST['day'];
$year = $_POST['year'];
error_reporting(0);
if(isset($_POST['clear'])) {
$month="";
$day="";
$year="";
}
?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
<div id="banner">
<h1 align="center">Day Checker</h1>
</div>
<br>
<form name="getDate" method="post" action="">
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td nowrap>
<font size="5" face="Arial, Helvetica, sans-serif">
Enter Date (mm/dd/yyyy):
</font>
</td>
<td nowrap>
<font size="5" face="Arial, Helvetica, sans-serif">
<input name="mon" type="text" size="12" maxlength="2" value="<?php echo $month; ?>" autofocus required>
/
<input name="day" type="text" size="12" maxlength="2" value="<?php echo $day; ?>" required>
/
<input name="year" type="text" size="12" maxlength="4" value="<?php echo $year; ?>" required>
</font>
</td>
<td nowrap>
<font size="5" face="Arial, Helvetica, sans-serif">
Example "04/12/2001"
</font>
</td>
</tr>
<tr>
<td>
<font size="5" face="Arial, Helvetica, sans-serif"> </font>
</td>
<td>
<font size="5" face="Arial, Helvetica, sans-serif">
<input type="submit" name="submit" value="Check Day" title="Click here to know the day in a given date">
<input type="submit" name="clear" value="Clear"
title="Click here to clear text box and values on the screen"/>
</font>
</td>
<td>
<font size="5" face="Arial, Helvetica, sans-serif"> </font>
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit'])) {
$fontStyle = "size=\"5\" face=\"Arial, Helvetica, sans-serif\"";
$dayStrings = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
if (!isset($month) || !isset($day) || !isset($year))
return;
if (($month < 1) || ($month > 12) ||
($day < 1) || ($day > 31) ||
($year < 0))
{
echo "<b>An invalid date ($month/$day/$year) was entered </b>";
return;
}
$t2 = array('0', '3', '2', '5', '0', '3', '5', '1', '4','6', '2', '4');
$year-= $month < 3;
$dow= ($year + $year/4 - $year/100 + $year/400 + $t2[$month-1] + $day) % 7;
echo "<font $fontStyle>";
if ($dow > 6) {
echo "<br>";
echo "Something is a miss, the day ($dow) is invalid";
} else {
echo "<br>";
echo "The day of the week for $month/$day/$year is:
<b><font color='red'> $dayStrings[$dow]</font>.</b>";
}
echo "</font>";
}
?>
</body>
</html>
No comments:
Post a Comment