sgalatas Posted November 28, 2007 Share Posted November 28, 2007 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/ Share on other sites More sharing options...
pocobueno1388 Posted November 28, 2007 Share Posted November 28, 2007 Exactly why are you trying to avoid using the date function? Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/#findComment-400877 Share on other sites More sharing options...
cooldude832 Posted November 28, 2007 Share Posted November 28, 2007 Such a formula does exist that you can turn a numerical MM/DD/YYYY into a specific day of the week, however I do not know of it, and I think its some guarded secret Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/#findComment-400882 Share on other sites More sharing options...
Barand Posted November 28, 2007 Share Posted November 28, 2007 1970-01-01 (unix time zero) was a Thursday. Use the timestamp for the date, convert to days, and calculate it from there. Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/#findComment-400953 Share on other sites More sharing options...
cooldude832 Posted November 28, 2007 Share Posted November 28, 2007 If you are that against the date function look at this http://mathforum.org/dr.math/faq/faq.calendar.html zeller's formula Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/#findComment-401169 Share on other sites More sharing options...
Barand Posted November 28, 2007 Share Posted November 28, 2007 Interesting reading. I guess Reverend Zeller didn't have access to Unix timestamps (but then again the unix epoch is a little limited compared with the whole of time) Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/#findComment-401407 Share on other sites More sharing options...
cooldude832 Posted November 28, 2007 Share Posted November 28, 2007 not really, its a generalized solution out of the scope of programing. Its all about the general solution first and then a specific use Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/#findComment-401619 Share on other sites More sharing options...
sgalatas Posted November 29, 2007 Author Share Posted November 29, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/#findComment-402459 Share on other sites More sharing options...
Barand Posted November 29, 2007 Share Posted November 29, 2007 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/#findComment-402468 Share on other sites More sharing options...
roopurt18 Posted November 29, 2007 Share Posted November 29, 2007 You could try the doomsday algorithm. Quote Link to comment https://forums.phpfreaks.com/topic/79199-solved-day-of-the-week-program/#findComment-402496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.