Results 1 to 7 of 7

Thread: Sorting Months Through date()

  1. #1
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755

    Sorting Months Through date()

    Hi all,

    In a database I've got the records with the normal date format, yyyy-mm-dd.

    I need to make a query which selects certain records depending on the month though, so does anyone know how I can do this?

    Cheers,
    Mike
    Don't you just love free internet games ?

  2. #2
    Registered
    Join Date
    Aug 2005
    Location
    ACT, Australia.
    Posts
    77
    Would something like this work? -

    SELECT * FROM table WHERE date like '%-12-%'

    (12 being the month number.)

  3. #3
    Working. Masetek's Avatar
    Join Date
    Aug 2005
    Location
    Aust
    Posts
    543
    Kate's hit the nail on the head. Thats how I'd do it

  4. #4
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    I'll give it a try, cheers folks
    Don't you just love free internet games ?

  5. #5
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Oh and while I'm at it...

    Does anyone know how I could make a group by query to fetch all the different months entered into the database? I'm not sure if it's similar to the method above or not...

    Thanks.
    Don't you just love free internet games ?

  6. #6
    Chronic Entrepreneur
    Join Date
    Nov 2003
    Location
    Tulsa, Oklahoma, USA
    Posts
    1,112
    Kate's solution will work great for selecting all dates from a certain month.

    If you're trying to do a GROUP BY month, you should probably use the MONTH() function. When given a date, it returns the numerical month of the date (1 - 12).

    For example:
    MONTH(2004-11-23)
    would return 11.

    Using the month function, you could do something like this:

    SELECT * FROM YourTable GROUP BY MONTH(yourDateField);

  7. #7
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Ah right, I didn't know there was a function like that. Thanks John...
    Don't you just love free internet games ?

Similar Threads

  1. Tribal Fusion - CPM Bad at months start?
    By Generalissimo in forum Advertising & Affiliate Programs
    Replies: 7
    Last Post: 07-08-2005, 05:23 PM
  2. 3 months FREE. 5000Mb Space. 10 Hosted domains.
    By Helen in forum The Marketplace
    Replies: 0
    Last Post: 11-18-2004, 08:21 AM
  3. Replies: 5
    Last Post: 11-13-2004, 08:06 PM
  4. Get Last Date Modified
    By XtrEM3 in forum Website Programming & Databases
    Replies: 1
    Last Post: 11-11-2004, 12:20 AM
  5. javascript date updating
    By rejean in forum Website Programming & Databases
    Replies: 2
    Last Post: 05-19-2004, 02:26 PM

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
  •