|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi, this might a very newbie question, but my date isn't displaying properly and I do not know why!!
I have something like this: Code:
<?php
$sql = "SELECT * FROM db_table WHERE Bpublished = '1' AND Bcater='$passed_cater' ORDER BY Bid DESC LIMIT $ppage, $limit";
$res = mysql_query($sql,$conn);
while ($row_blog = mysql_fetch_array($res)) {
echo date('d M Y', $row_blog['Bdate']);
};
?>
I've tried variations of it, such as Code:
echo date('r', $row_blog['Bdate']);
Code:
echo date('m-d-y H:i:s', $row_blog['Bdate']);
I don't have any entries with that date, so why is it doing that?? I'm very frustrated and I can't seem to get any answers in google!! Please help!! ![]() ![]() ![]()
|
|
#2
|
||||
|
||||
|
You are facing a funny problem!
The first defined date is January 1, 1970. So what you receive, the day before the first defined date in php, means that the value of $row_blog['Bdate'] is -1 .This means that mysql is returning an error while connecting the database, reading the entry, or something else. The sure thing is that the problem is in your database query, and not the date function and format. Good luck! |
|
#3
|
||||
|
||||
|
More likely you are getting an empty value, a zero, or a string that evaluates as zero when converted to an integer, and your server's time zone is somewhere west of the Prime Meridian. Unless the value being returned by your query is a UNIX timestamp integer, then it is not ready to be used as the 2nd parameter for date(). You may need to convert it with something like strtotime() first:
PHP Code:
__________________
"That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett freelancer.internet.com Email me |
|
#4
|
|||
|
|||
|
Quote:
Still frustrated! hehe
|
|
#5
|
|||
|
|||
|
Quote:
)I tried strtotime() but it returns the same value. I think my time zone setup for mySQL is correct. Because when I echo the actual date row, I get the right dates, such as 2009-11-05. It is only when I try to apply a date() format to it that it seem to stuff up!
|
|
#6
|
||||
|
||||
|
What do you get if you just echo out $row_blog['Bdate'] instead of using any of the date functions? (In other words, we need to find out what the original value is that you're using.)
__________________
"That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett freelancer.internet.com Email me |
|
#7
|
|||
|
|||
|
Quote:
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|