SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Outputting a list of dates

    Hi Guys,

    I have a list of dates in a database for various months ie: January, February, March etc... and they are all saved in a mysql database ie:

    2007-01-01
    2007-01-02
    2007-02-01
    2007-02-02
    2007-03-01
    2007-03-02

    My question is is there anyway I can split these dates up into months. Ie pull all the dates for January into one html table using php, then create another table to pull in all the February dates and so on?

    Many Thanks

    Chris

  2. #2
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $sql = "SELECT * FROM dates WHERE MONTH(date_listing) = 1"; 
    //Will output all months in January

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Here's an example of how you'd select only months from a table which contained a column called "birth" which was a type "date".

    mysql> SELECT name, birth, MONTH(birth) FROM pet;

    read more here:

    http://dev.mysql.com/doc/refman/5.0/...culations.html

    In your case to get only dates in Feb 2007 you would want your selects to select only your select then " .... where year(column) = 2007 and month(column_name) = 2 ".

    remember that field must be a date (or time) type field- not a varchar containing 2007-03-01

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, I have a date field - cheers guys


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
  •