Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2003
    Posts
    328

    Unanswered: 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.

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •