Page 1 of 1

Displaying Day of the Week

Posted: Thu Mar 04, 2010 4:43 pm
by voicebox
Hello,
I am trying to understand how I can display the day of the week for a date that has been entered into a MySQL DB.

As you can see from the link below, just the date is showing. What code do you I add so it will show that dates day of the week.

http://stceciliak8.org/teachers/homework_Results.php

I have attached the code too.

Thank you

Re: Displaying Day of the Week

Posted: Thu Mar 04, 2010 5:14 pm
by olidenia
Hi, maybe this will help:

// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));


Got it from:
http://php.net/manual/en/function.date.php

Re: Displaying Day of the Week

Posted: Thu Mar 04, 2010 5:43 pm
by voicebox
Cool, so how would I convert this to include the day of the week.

<?php echo($row_WADAhomework['due_date']); ?>

Thanks

Re: Displaying Day of the Week

Posted: Thu Mar 04, 2010 6:09 pm
by olidenia
First chop the MySQL date up into three variables - $year, $month and $day.

Then use a combination of the mktime() and date() commands. Mktime can turn $month/$day/$year into a Unix timestamp and then date() turns the timestamp into a string formatted however you like. For example:

$weekday = date("l", mktime(0,0,0,$month,$day,$year));
$print ($weekday);

Will print out the day of the week spelled in full.

Check the manual for details on the date and mktime functions:
http://php.net/manual/en/function.date.php

Re: Displaying Day of the Week

Posted: Thu Mar 04, 2010 8:10 pm
by requinix
Or instead of all that, DATE_FORMAT.