Day of week

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JWDGS
Forum Newbie
Posts: 2
Joined: Tue Oct 06, 2009 9:15 am

Day of week

Post by JWDGS »

I am using PHP version 5.0.5
I have a varaible ($DATE (date format yyyy-mm-dd)) that is being incremented to populate a table with each day of the month. I am then trying to get the day of week (preferably an integer) for each date in the month. I have tried both
$DOW = date("w", $Date)
and
$DOW = date("l", $Date)

Using October of this year however $DOW always returns either "3" or "Wednesday". I have checked and the varaible $Date is incrementing correctly. Here is the code snippet:

for ($num = 1; $num <= $Count; $num++) {
if($num < 10)
$SDPart = "0$num";
else
$SDPart = "$num";
$Date = "2009" . "-" . $SDMo . "-" . $SDPart;

$DOW = date("w", $Date);
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Day of week

Post by Mark Baker »

date() requires a date/timestamp, not a formatted string, as the second parameter.

Code: Select all

$DOW = date("w", strtotime($Date));
or

Code: Select all

$DOW = date("w", mktime(0,0,0,$SDMo,$SDPart,2009));
JWDGS
Forum Newbie
Posts: 2
Joined: Tue Oct 06, 2009 9:15 am

Re: Day of week

Post by JWDGS »

Works perfectly. Thanks for the help!
Post Reply