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
#2
Thanks, this is cool.
Reply
#3
That is nice. Will use this on my homepage, thanks.
Reply
#4
haha funny little add-on!

niice!
Reply
#5
wow its cool
Reply
#6
Thanks Mattr

nice sharing
[Image: 2d75599e9a.png]:superman:
Reply
#7
Nice tidy code MattR.
Expected nothing less but i do have a question regarding this.
What did you use to write this. What i mean is did you hand code it all in something like notepad etc?
Or from within a editor like Dreamweaver.
Main reason i ask is the indenting which i see. Very typical of dreamweaver to do it and certainly concidered standard.
Just curious is all to be honest.
The Rules!
FTW Forum <-- Home of the Damned! --> Join me On MM


Reply
#8
I use Notepad++, I prefer to write it myself and just have syntax highlighting so I can see if something isn't right. The indenting is mainly just for readability/structure.
MyBB Support Team Lead
Reply
#9
Cool thanks MattR. Very tidy work mate.
The Rules!
FTW Forum <-- Home of the Damned! --> Join me On MM


Reply


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 773 07-27-2020, 11:26 PM
Last Post: tk-hassan
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,264 10-10-2011, 01:00 PM
Last Post: Greyersting

Forum Jump:


Users browsing this thread: 1 Guest(s)