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
Displaying Day of the Week
Moderator: General Moderators
Displaying Day of the Week
- Attachments
-
- homework_Results.php.zip
- (2.73 KiB) Downloaded 73 times
Re: Displaying Day of the Week
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
// 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
Cool, so how would I convert this to include the day of the week.
<?php echo($row_WADAhomework['due_date']); ?>
Thanks
<?php echo($row_WADAhomework['due_date']); ?>
Thanks
Re: Displaying Day of the Week
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
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
Or instead of all that, DATE_FORMAT.