note 34436 added to function.date
| From: | danolesen at excite dot com | Date: | Sun, 27 Jul 2003 07:00:54 +0000 |
| Subject: | note 34436 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52736@lists.php.net to get a copy of this message | ||
When dates screw up !!!!
I am sure you've tried getting a date from a search in MySQL, which becomes:
"jan. 1 1970 00:00:00",
when you try to display it formatted with the date() function.
WHY !! - because it becomes a string when you get it from a row.
You need to make it a real date before the date() function will give you the string you need.
Look at this:
$query = "SELECT enq_date FROM enq WHERE id = $id";
$rSetE = mysql_query($query, $lnk);
$rowE = mysql_fetch_row($rSetE);
$enq_date = $rowE[0]; // the date is now a string
using the unformatted $enq_date in a print will yield the right date but in an ugly format:
print $enq_date;
will output
2003-07-03 23:10:46
using the date() function directly on $enq_date will however not quite work:
print date("d-m-Y H:m",$enq_date);
will output
01-01-1970 00:00
Now you may have the desired format but a wrong date. The solution is:
print date("d-m-Y H:m", strtotime($enq_date));
will output
03-07-2003 10:46
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34436
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34436&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34436&report=yes