RE: [PHP] date() formatting

From: Date: Thu, 24 Aug 2000 14:55:40 +0000
Subject: RE: [PHP] date() formatting
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-13432@lists.php.net to get a copy of this message
> -----Original Message----- > From: Matt McClanahan [mailto:cardinal@dodds.net] > Sent: Wednesday, August 23, 2000 3:31 PM > To: O.J. Alcaraz > Cc: 'php-general@lists.php.net' > Subject: Re: [PHP] date() formatting > > > On Wed, 23 Aug 2000, O.J. Alcaraz wrote: > > I have a field of type datetime. I would like to format the > record so that it displays for example, 'Wed, August 23, 2000 > 12:40:33' I already tried doing date("D M d, Y H:i:s", > $rs["date"]) but I keep getting Jan 01, 1970 00:33:20 date. > There is no problem with pulling the record as it displays > the MMMM-YY-DD HH:II:SS format. Is there anything I am missing > or doing wrong? Thanks. PHP's date() function expects a Unix timestamp, which represents the number of seconds since midnight on Jan 1, 1970. For what you're trying to do, you'll likely need to either (a) use substr() and mktime() to convert your YYYY-MM-DD HH:II:SS into a proper Unix timestamp before feeding it into date(), or (b) look into your database engine's capabilities and see whether it'll format the date for you. If you're using MySQL, the function you'll want to use in your query is date_format(), and it's documented at http://www.mysql.com/documentation/mysql/commented/manual.php?section=Date_a nd_time_functions --- Mark Roedel | "Blessed is he who has learned to laugh Systems Programmer | at himself, for he shall never cease LeTourneau University | to be entertained." Longview, Texas, USA | -- John Powell

« previous php.general (#13432) next »