0

How can i show this as a DAY rather than full date

echo "<td align='left' valign='middle' bgcolor='" . $color . "'><font size='" . $fontsize . "'>" . $row['date'] . "</td>"; 

i already have

date_default_timezone_set('Europe/London'); 

i have a similar question already asked but mistakenly put it as MYSQLi but i need MYSQL PHP support on this

the date and time is correctly set for the timezone but on viewing the PHP i want to view it as a Day

3 Answers 3

2

Use the date() function in PHP to change the date format...

date('l',strtotime($row['date'])); 

So your code changes to this...

echo "<td align='left' valign='middle' bgcolor='" . $color . "'><font size='" . $fontsize . "'>" . date('l',strtotime($row['date'])) . "</td>"; 

Info on date()

Date can display in many different ways...

date('Y-m-d'); //2013-06-17 format date('z'); //day of the year date('l'); //textual day of week 

See here for details...

http://php.net/manual/en/function.date.php

UPDATE

You are having trouble with the format, so you can fix it like this...

$date = explode(" ",$row['date']); $date2 = explode("/",$date[0]); $displayDay = date('l',strtotime($date2[2]."-".$date2[1]."-".$date2[0])); 

Then just echo that line with

echo "<td align='left' valign='middle' bgcolor='" . $color . "'><font size='" . $fontsize . "'>" . $displayDay . "</td>"; 
Sign up to request clarification or add additional context in comments.

3 Comments

i tried the above and i get 17/06/2013 0:32:55 am showing as THURSDAY which is wrong because it should show as MONDAY
Well thats probably the strtotime function screwing up your date, you may have to filter it twice...what is the exact format of your date....when echoed in PHP?
yes when i echo "<td align='left' valign='middle' bgcolor='" . $color . "'><font size='" . $fontsize . "'>" . date('l',strtotime($row['date'])) . "</td>"; it shows as THURSDAY for today
0

what is your current output and how do you want it to be? probably something like date('d m Y', $row['date'])but that depends heavily on the column type of your date col.

1 Comment

i already have that set on INSERT INTO date_default_timezone_set('Europe/London'); $date = date('d/m/Y G:i:s a', time()); so it would output for me 17/06/2013 0:32:55 am
0

assumed 17/06/2013 0:32:55 am is your output on $row[date]:

something like this:

$date = DateTime::createFromFormat('d/m/Y G:i:s', $row[date]); echo date('D', $date->getTimestamp()); 

I didn't check for the format operators, but that's easy to look up

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.