note 34279 added to function.date
| From: | Jonathan at rack1 dot php dot net | Date: | Mon, 21 Jul 2003 01:34:22 +0000 |
| Subject: | note 34279 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52437@lists.php.net to get a copy of this message | ||
I had this problem that I noticed other people are having with trying to get the MySQL date that was
inserted into the database (created in MySQL like this: my_date date DEFAULT '0000-00-00'
NOT NULL) to convert into something the typical humanoid is more capable of reading. Something
familiar. So the date gets inserted into the database in a format like this: 2003-06-12, but I want
it to look like this: 'Thursday, 12 June 2003'. I did a the database query using PHP for
the date, put it in the variable name $my_date, and wanted to convert that using the strtotime();
function. The problem I always ended up with the year being 1969, while everything else was correct.
I am not sure why, but it scared me, so I messed around a little bit. I ended up finding a very good
solution, which is also very simple. Check it out.
$date_created = date('l, d F Y',strtotime($row["my_date"]));
This gives me the string in the format I wanted. Knowing this, I can easily take any MySQL date and
format it to any way I choose, gregorian calendarwise. I hope that helps people out with similar
problems formatting dates.
Ciao,
Jonathan
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34279
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34279&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34279&report=yes