If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Using date in an equation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-03-04, 15:41
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
Using date in an equation

I am trying to create a query that retrieves all records that are older than 2 weeks. The query I have now is:

select * from my_table
where my_date>date_format(now(),'yyyy-mm-dd')-13

This retrieves all records in my table. Any suggestions? Thanks.
Reply With Quote
  #2 (permalink)  
Old 06-04-04, 07:37
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
date_format merely changes the way a date is output, you want to use date_sub.

Here is the solution straight from the MySQL manual:

Code:
Here is an example that uses date functions. 
The following query selects all records with a date_col value 
from within the last 30 days:

mysql> SELECT something FROM tbl_name
    -> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On