RE: [PHP] Output yyyymmdd formatted date || 20030131 to FridayJanuary 31, 2003

From: Date: Sat, 08 Feb 2003 23:31:44 +0000
Subject: RE: [PHP] Output yyyymmdd formatted date || 20030131 to FridayJanuary 31, 2003
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-134909@lists.php.net to get a copy of this message
> The dates are stored in a MySql db. > > I checked out the MySql DATE_FORMAT function -- pretty cool. > > However, pardon my ignorance here, how can I do date comparisons? > > For example, if I want to retrieve records from the db where the date is > between say, 2003-02-01 and 2003-02-07, will MySql be able to compare the > strings? > > I stored my dates as integer fields to do such a comparison, but it looks > like I need to graduate to MySql date time functions.......... If you've done it correctly and stored your dates in a MySQL DATE, DATETIME, or TIMESTAMP column, then you can do something like this: SELECT * FROM table WHERE yourdate BETWEEN 20030201 AND 20030207 If you're storing them in an INT column, then change it over to one of the above. Go back to the manual and read about date_sub() and date_add() in MySQL for further date manipulation... ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#134909) next »