Day of the Week Script?

EricVonDoobie

FAQ it
Dec 23, 2009
3,214
59
0
Sunnyvale Trailer Park
I'm looking for a script that does nothing other than display the user's day of the week. i.e. "Wednesday" or "Monday" depending on which day it is for the user. I looked around and couldn't find a single thing that did this--any suggestions? I'd really appreciate it.
 


Are you using the user's IP to guess the time zone? Not reliable, but I'm not sure how else you would do it.
 
First get time zone from browser - then convert using the gmdate function in php to get the date...
i.e.
<?php
if (isset($_GET['offset'])) {
$minutes = $_GET['offset'];
echo "GMT offset (in minutes, from the browser): ". $minutes ."<br />\n";
echo "GMT: ". gmdate("Y-m-d H:i:s") ."<br />\n";

$local = gmmktime(gmdate("H"),gmdate("i")-$minutes); // adjust GMT by client's offset

echo "Calculated client's date/time: ". gmdate("Y-m-d h:i:s a",$local) ."<br />\n";
} else {
echo "<script language='javascript'>\n";
echo "var d = new Date();\n";
echo "location.href=\"${_SERVER['SCRIPT_NAME']}?offset=\" + d.getTimezoneOffset();\n";
echo "</script>\n";
exit();
}
?>

Now then that just was a script to echo out the offset... set 'em to variables then just use the date function to figure out the day of week..
// let's say they're in the timezone GMT+10
$theirOffset = 10; // $_GET['offset'] perhaps?
$offsetSeconds = $theirOffset * 3600;
echo gmdate("l", time() + $offsetSeconds);

datetime - How to find day of week in php - Stack Overflow