Formatting Date DataType
Moderator: General Moderators
Formatting Date DataType
I have a column in a MySQL database with a DATE as the data type. When outputting, it appears like "2005-01-23". I am on a Windows machine running the latest PHP. I am trying to make it appear like this, "Sunday, Jan. 23, 2004". Any ideas?
YES!
Got it! Thanks. I changed my query to read:
Code: Select all
SELECT *, DATE_FORMAT('datecolumn','%a, %b %e, %Y') FROM tableIt's like this. If I echo the dry record, it appears like this: "2005-01-20". When I used the MySQL code posted above, I would get the same dry output as before. Why? Because my "DATE_FORMAT(..)" statement did not have a "AS showDate" so I could not echo the actual formatted record. When I figured that out, I echoed the formatted record and nothing appeared. So it did not work at all. I was just echoing the actual record without any formatting.
The datatype is DATE. It appears like "0000-00-00". I need it to appear like "MM-DD-YYYY".
By the way, I'm on a Windows server if that matters. 2000 I believe.
The datatype is DATE. It appears like "0000-00-00". I need it to appear like "MM-DD-YYYY".
By the way, I'm on a Windows server if that matters. 2000 I believe.
Here is what I get with this query:
and code:echos:
This code:echos (literal record):
This code:...and this code:echos:
Code: Select all
SELECT *, UNIX_TIMESTAMP(eventDateIN) AS eventDateINshow FROM con_eventsCode: Select all
<?php echo $row_eventsLISTmodї'eventDateINshow']; ?>Code: Select all
1109311200Code: Select all
<?php echo $row_eventsLISTmodї'eventDateIN']; ?>Code: Select all
2005-02-25Code: Select all
<?php echo date('m-d-Y', $row_newsLISTї'eventDateINshow']); ?>Code: Select all
<?php echo $row_newsLISTї'eventDateINshow']; ?>Code: Select all
12-31-1969well, you select it as a date string... and then you feed it to a function that is expecting a unixtimestamp... that is why you are getting weird output...
anyway, as already suggested just
allows you to skip the php manipulation....
anyway, as already suggested just
Code: Select all
SELECT DATE_FORMAT(eventDateIN, 'm-d-Y') AS eventDateINshow FROM con_eventsyou could manipulate it with php too using date() and strtotime().
something like
you could then add some time stuff in there too if you wanted
Burr
something like
Code: Select all
$bob = mysql_query("select date from mytable");
if($robert = mysql_fetch_assoc($bob)){
echo date("l M d, Y", strtotime($robertї'date']));
}Burr