[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql
Subject:    Re: date problem
From:       Michael Widenius <monty () monty ! pp ! sci ! fi>
Date:       1999-06-27 22:46:18
[Download RAW message or body]

>>>>> "Paul" == Paul DuBois <paul@snake.net> writes:

Paul> At 6:31 AM -0700 6/24/99, Dan Parisien wrote:
>> I couldn't find a good enough example in the documentation,
>> I have a table with created_on date fields, I want to query created on fields
>> created in the last 5 days or something,
>> do I do curdate()+5 ??
>> Im not sure how,
>> thanks,
>> Dan P


Paul> Something like that, though you might want curdate()-5 instead. :-)

mysql> create table t (date date);
mysql> insert t values("1999-6-23"),(19990622),(19990620),(19990618);
mysql> select * from t;
Paul> +------------+
Paul> | date       |
Paul> +------------+
Paul> | 1999-06-23 |
Paul> | 1999-06-22 |
Paul> | 1999-06-20 |
Paul> | 1999-06-18 |
Paul> +------------+
mysql> select * from t where date < curdate()-5;
Paul> +------------+
Paul> | date       |
Paul> +------------+
Paul> | 1999-06-18 |
Paul> +------------+

The above is not correct (- doesn't work realiable with dates).

Use instead:

select * from t where date < DATE_SUB(curdate(),INTERVAL 5 days);

Regards,,
Monty

*************** Warning commercial signature follows **********
If you like TCX's concept of a 'mostly free' database and free
advice, you should at least CONSIDER supporting us that we can
afford to keep this service up.   http://www.mysql.com/

---------------------------------------------------------------------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail mysql-thread6013@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail mysql-unsubscribe@lists.mysql.com instead.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic