Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    8

    Unanswered: Selecting "month/year" from table

    Hi,

    I have a table in a mysql db with a date column. I would like to retrieve a list of distinct month/year values from the table.

    Any ideas how to formulate the sql query? For example, I know I could use:

    select distinct month(date_field) from table_name

    but this doesn't take into account the year.

    Thanks!

    (I tried asking this on another and got no answer - my apologies to anyone who reads this twice)

  2. #2
    Join Date
    Aug 2004
    Posts
    4
    try this TO_CHAR(Name_of_date_field, 'MM/YY') <--- this would take the 2 digits for month and year

  3. #3
    Join Date
    Jan 2004
    Posts
    8
    Thanks, Lindsey. That did the trick. (though since I am using mysql, I had to substitute to_char with date_format)

    It was really simple, but I couldn't get it on my on. The other forum I had asked on berated me a bit and I was quite frustrated.

    Thanks again for your help.

  4. #4
    Join Date
    Aug 2004
    Posts
    4
    you are welcome, and now i'm stuck with the tab-delimited hehe.. i'm supposed to write a query and the output should be tab-delimited format, but i don't know how to formulate the query

Posting Permissions

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