Re: Output yyyymmdd formatted date || 20030131 to FridayJanuary 31, 2003
| From: | Noah | Date: | Sun, 09 Feb 2003 03:20:16 +0000 |
| Subject: | Re: Output yyyymmdd formatted date || 20030131 to FridayJanuary 31, 2003 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134917@lists.php.net to get a copy of this message | ||
Right.
I've switched the date column from type INT to type DATE in our MySql db.
The problem I've had with retrieving records in a certain date range with:
SELECT * FROM table WHERE yourdate BETWEEN 20030201 AND 20030207
is getting the latter part of the expression; i.e. in this case 20030207 to
be seven days "older" than the first part.
This is where I need to use MySql's DATE_ADD, and other date manipulation
functions..........
Lots to learn; little time to do it.
Thanks for feedback, John.
--Noah
----- Original Message -----
From: "John W. Holmes" <holmes072000@charter.net>
To: "'Noah'" <noah@newminddesign.com>; <operations@cdmsports.com>
Cc: <php-general@lists.php.net>
Sent: Saturday, February 08, 2003 3:31 PM
Subject: RE: [PHP] Output yyyymmdd formatted date || 20030131 to
FridayJanuary 31, 2003
> > 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/
>
>