Jump to content

extracting year from date


40esp

Recommended Posts

Right now i hate this sql:

 

SELECT * FROM lookup LEFT JOIN publications ON publications.id = lookup.publication_id WHERE publications.date>='$archive_year%' AND publications.type='News Letter' AND publications.archive='Active' AND lookup.practice_group_id='$practice_id' ORDER BY 'date' DESC

 

in php $archive_year would look like:    2005    for example.

 

And the field publications.date would be something like: 2005-06-06

 

I think the WHERE publications.date>='$archive_year%'  is whats causing my problem. The problem is, it doesn't filter the results right, I want to only display records with the date of 2005, but it gives me 2006, and 2004 records as well. How would I shape up the sql?

Link to comment
Share on other sites

Talking bout that year thing, yes, there is a work around for that. use,

 

... WHERE YEAR(publications.date) >= '" . $archive_year . "' ...

 

actually you can also do:

 

... WHERE YEAR(publications.date) >= '$archive_year' ...

 

but I do not really use such method (personal preference :D).

 

Jay,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.