SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast Ckeren's Avatar
    Join Date
    Jun 2001
    Location
    AU
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Filtering date from MySQL

    Hi guys I'm a little bit stuck with mysql query

    Need to get YEAR(date) value only from MySQL table where YEAR(date) is actually from the least to current year.

    for example inside my database date attribute exists alot of dates and only need to get the years values, such as if dates are: 2000-01-13, 2001-01-13, 2001-02-23, 2002-01-13

    the query will only return values: '2000', '2001' and '2002' only

    Thank you in advance

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried something like:

    SELECT YEAR(dateColumn) AS yearAlias
    FROM TableName
    ORDER BY yearAlias ASC

  3. #3
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You could use the DISTINCT clause to extract one of each year:

    SELECT DISTINCT YEAR(dateColumn) AS yearAlias
    FROM TableName
    ORDER BY yearAlias ASC

    ============

    Derrick
    http://www.bibliology.com

  4. #4
    SitePoint Zealot
    Join Date
    May 2001
    Location
    UK
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If dates are in like "2000-01-13" you could just select 4 charectors from left.

    So wouldn't it be ...
    select LEFT(date,4) etc.
    Please take a minute to do The Ecommerce Survey
    You get a free information security report as a thank you!
    [ More info on report | The Ecommerce Survey ]


Bookmarks

Posting Permissions

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