I tried to use the following to get the week day of a date without success: No matter what the date in database is, it will all print out Wednesday. The date was recorded as date("Y/m/d"). And I tried the same script on different servers, still the same. What's wrong with the script?
<?php $time = date(l); echo $time; ?> PHP: The "l" in the parentheses is for the day of the week, Monday - Sunday . Full database insertion and stuff: <?php $time = date(l); echo "Today is: $time "; $db_host = "localhost"; $db_user = "username"; $db_pwd = "password"; $db_name = "database"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); if($time == "Thursday") { mysql_query("INSERT INTO time (time) VALUES ('$time')"); { echo "Thursday? Wow, that's a day of the week!"; } } else { mysql_query("INSERT INTO time (time) VALUES ('$time')"); { echo "The date of $time was inserted into the database!"; } } ?> PHP:
I already recorded all the date with the format of date("Y/m/d"), now I want to get the week day of the date.
the problem is the getdate() read timestamps. convert the $sDate to timestamp first. $sDate = strtotime($list['date']); // continue with your script PHP: it should work now. This is another way: $date = '2008/9/24'; // or your $list['date'] $timestamp = strtotime($date); // make it a timestamp $weekday = date("l",$timestamp); // the weekday print $weekday; PHP: