Displaying Day of the 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
voicebox
Forum Newbie
Posts: 2
Joined: Thu Mar 04, 2010 4:37 pm

Displaying Day of the Week

Post 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
Attachments
homework_Results.php.zip
(2.73 KiB) Downloaded 73 times
olidenia
Forum Newbie
Posts: 19
Joined: Mon Apr 28, 2008 12:38 pm

Re: Displaying Day of the Week

Post 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
voicebox
Forum Newbie
Posts: 2
Joined: Thu Mar 04, 2010 4:37 pm

Re: Displaying Day of the Week

Post by voicebox »

Cool, so how would I convert this to include the day of the week.

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

Thanks
olidenia
Forum Newbie
Posts: 19
Joined: Mon Apr 28, 2008 12:38 pm

Re: Displaying Day of the Week

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Displaying Day of the Week

Post by requinix »

Or instead of all that, DATE_FORMAT.
Post Reply