Re: converting DATETIME to a readable date.
| From: | Plutarck | Date: | Sun, 15 Apr 2001 09:51:13 +0000 |
| Subject: | Re: converting DATETIME to a readable date. | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48625@lists.php.net to get a copy of this message | ||
The I "now" get a date from MySQL (hehe) is to use UNIX_TIMESTAMP then feed
it over to date.
That way if I want to change the way the date is displayed, I don't have to
touch my query syntax. And I personally find it easier to use PHP's date()
function rather than MySQL's.
--
Plutarck
Should be working on something...
...but forgot what it was.
"Chris Adams" <chris@improbable.org> wrote in message
news:slrn9dhtc5.k1g.chris@gigante.improbable.org...
> On 14 Apr 2001 17:31:02 -0700, DRN <donaldrnoble@NOSPAM.yahoo.com> wrote:
> >$date = $row["date"];
> >
> >$new_date = date("l, j M Y, G:i:s", strtotime($date));
> >~~
> >
> >but I cannot get this to work :(, I get an "unexpected error in
> >date()"
>
> At a guess strtotime() is choking on the format MySQL used to return the
date,
> which would lead date() to fail as well.
>
> The best way of handling this is to eliminate the need for your program to
> worry about the day formats. Modify your mysql query so that instead of
"SELECT
> date" you have something like "SELECT UNIX_TIMESTAMP(date) AS date". Then
you
> can simply use date($row["date"]) directly. Alternately, you could use
MySQL's
> date formatting function to return the desired format directly. In either
case,
> you'll save a great deal of trouble by avoiding the need for PHP and MySQL
to
> be parsing each other's human-readable date formats.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>