Re: converting DATETIME to a readable date.

From: Date: Sun, 15 Apr 2001 01:12:37 +0000
Subject: Re: converting DATETIME to a readable date.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-48611@lists.php.net to get a copy of this message
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.

« previous php.general (#48611) next »