Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2008
    Location
    Leuchars, Scotland, UK
    Posts
    51
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Querying a time format

    Hi,

    Im creating a blog ... when I click on a date (March-2009) I want msql to query all the posts in March-2009

    obviously the database has stored the date as something like "2009-03-01"

    Im playing around with the query:
    PHP Code:
    SELECT FROM blog WHERE blogdate DATE_FORMAT('March-2009' '%M-%Y'ORDER by blogdate DESC 
    but it doesnt seem to do anything..

    am I barking up the wrong tree (ie. wrong msql command)

    Thanks

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    PHP Code:
    SELECT FROM blog WHERE DATE_FORMAT(blogdate '%M-%Y') = 'March-2009' ORDER by blogdate DESC 
    John

  • Users who have thanked PappaJohn for this post:

    Trinity-Links (03-08-2009)

  • #3
    New Coder
    Join Date
    Mar 2008
    Location
    Leuchars, Scotland, UK
    Posts
    51
    Thanks
    19
    Thanked 0 Times in 0 Posts
    cheers very muchly....

    I can see where I went wrong now....Mind u, it is past me bed time!

    Thanks again

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    You're welcome
    John

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,111
    Thanks
    75
    Thanked 4,333 Times in 4,299 Posts
    I think you will find you will get better efficiency if you code
    Code:
    SELECT * FROM blog 
    WHERE YEAR(blogdate) = 2009 AND Month(blogdate) = 3
    ORDER by blogdate DESC
    I assume you can easily pass in the numbers 2009 and 3 (or whatever) from whatever server language you are using.


  •  

    Posting Permissions

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