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 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation pulling out data from a db where the date field equals current yr?

    Hi

    i am trying to pull out the news stories from a db where the dateSubmitted is equal to the current year, the problem is the dateSubmitted is stored as a date (2009-10-13) so how do i pullout the records where the year equals the current year?

    here is my code
    PHP Code:
    $currentYear date('Y');
    print 
    $currentYear;
    $getNews "SELECT news_headline FROM news WHERE dateSubmitted = '$currentYear' ORDER BY dateSubmitted ASC";
    $sql mysql_query($getNews);
    while(
    $newsStories mysql_fetch_array($sql))
    {
        print 
    $newsStories['news_headline'];

    nothing is printing out, so i assume that ive got to do something to the date which is stored in the db first to get this to work?

    thanks
    Luke

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,036
    Thanks
    2
    Thanked 316 Times in 308 Posts
    WHERE YEAR(dateSubmitted) = '$currentYear'

    or you don't even need any php code -

    WHERE YEAR(dateSubmitted) = YEAR(CURDATE())
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    LJackson (10-13-2009)

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    Thanks mate!!!!


  •  

    Posting Permissions

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