Results 1 to 4 of 4

Thread: MySQL statment

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    MySQL statment

    I need to do a query on a MySQL table. I need to select records that are greater than a particular date. the problem is, the field was created as a varchar. how can I do a comparison of dates in this case?

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    .

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Are the values all in exactly the same format? if not you'll probably have major hassle working it out!

    What you need to do is somehow split the field into the three parts (d, m, and y), preferably in a numeric format.

    Then you can do a where clause like the following:
    Code:
    WHERE y > specific_year
    OR (y = specific_year 
         AND (  (m > specific_month) 
                 OR (  (m= specific_month)
                       AND (d> specific_day) 
                      )
                 )
        )

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    OK...

    1) Find out the convert to date function in MySql's Sql statement - concatinate the three fields and use...
    2) Concatinate the three fields together yyyymmdd (note the months and days must be in two digits with leading 0) - sort and see if that helps with filtering.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width