Support Forums
Find day of the week with PHP - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: Find day of the week with PHP (/showthread.php?tid=198)



Find day of the week with PHP - MattR - 10-05-2009

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.


RE: Find day of the week with PHP - JonP - 10-05-2009

Thanks, this is cool.


RE: Find day of the week with PHP - faviouz - 10-05-2009

That is nice. Will use this on my homepage, thanks.


RE: Find day of the week with PHP - Extasey - 10-05-2009

haha funny little add-on!

niice!


RE: Find day of the week with PHP - HuNt3R - 10-11-2009

wow its cool


RE: Find day of the week with PHP - Akshay* - 10-12-2009

Thanks Mattr

nice sharing


RE: Find day of the week with PHP - DAMINK™ - 10-13-2009

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.


RE: Find day of the week with PHP - MattR - 10-13-2009

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.


RE: Find day of the week with PHP - DAMINK™ - 10-13-2009

Cool thanks MattR. Very tidy work mate.