Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find day of the week with PHP
#1
This will tell you the day of the week of any date you put in. I've done it to tell you the day you were born on but that's just what I initially made it for. This is something I did ages ago when I started learning PHP but this version is like a tenth the size of the original version, now that i understand mktime()

PHP Code:
<html>
<
head>
<
title>Birthday Calculator</title>
<
style type="text/css"
.
text {
color#000000;
font-family"Trebuchet MS";
}
</
style>
</
head>
<
body>
<
form method="get" action="">
    <
span class="text">Date:</span>
    <
select name="date" class="text">
        
        <
option value=""></option>
    <?
php
    
for($i=1;$i<=31;$i++)
    {
        
?>
        
        <option value="<?php echo $i?>"<?php if($_GET['date'] == $i) { echo " selected=\"selected\""; } ?>><?php echo $i?></option>
        <?php
    
}
    
?>
    
    </select>
    <?php
    $months 
= array("1" => "January",
                    
"2" => "February",
                    
"3" => "March",
                    
"4" => "April",
                    
"5" => "May",
                    
"6" => "June",
                    
"7" => "July",
                    
"8" => "August",
                    
"9" => "September",
                    
"10" => "October",
                    
"11" => "November",
                    
"12" => "December"
                    
);
    
?>
<span class="text">Month:</span>
    <select name="month" class="text">
        
        <option value=""></option>
        <?php
        
foreach($months as $mid => $month)
        {
            
?>
        
        <option value="<?php echo $mid?>"<?php if($_GET['month'] == $mid) { echo " selected=\"selected\""; } ?>><?php echo $month?></option>
            <?php
        
}
        
?>
        
    </select>
    <span class="text">Year:</span>
    <select name="year" class="text">
        
        <option value=""></option>
    <?php
    
for($i=2009;$i>=1900;$i--)
    {
        
?>
        
        <option value="<?php echo $i?>"<?php if($_GET['year'] == $i) { echo " selected=\"selected\""; } ?>><?php echo $i?></option>
        <?php
    
}
    
?>
    
    </select>
    <input type="submit" class="text" value="Submit" />
</form>
<?php
if($_GET)
{
    foreach(
$_GET as $key => $val)
    {
        
$_GET['$key'] = htmlspecialchars($val);
    }
    
$day_of_week date("l"mktime(000$_GET['month'] , $_GET['date'] , $_GET['year']));
    echo 
"<span class=\"text\">You were born on a " $day_of_week "</span>";
}
?>
</body>
</html> 

Put in your DoB and it'll say what day it was.
MyBB Support Team Lead
Reply


Messages In This Thread
Find day of the week with PHP - by MattR - 10-05-2009, 11:12 AM
RE: Find day of the week with PHP - by JonP - 10-05-2009, 11:27 AM
RE: Find day of the week with PHP - by faviouz - 10-05-2009, 11:39 AM
RE: Find day of the week with PHP - by Extasey - 10-05-2009, 06:51 PM
RE: Find day of the week with PHP - by HuNt3R - 10-11-2009, 09:33 AM
RE: Find day of the week with PHP - by Akshay* - 10-12-2009, 07:09 AM
RE: Find day of the week with PHP - by DAMINK™ - 10-13-2009, 02:12 AM
RE: Find day of the week with PHP - by MattR - 10-13-2009, 02:42 AM
RE: Find day of the week with PHP - by DAMINK™ - 10-13-2009, 02:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 786 07-27-2020, 11:26 PM
Last Post: tk-hassan
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,300 10-10-2011, 01:00 PM
Last Post: Greyersting

Forum Jump:


Users browsing this thread: 1 Guest(s)