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
https://forums.phpfreaks.com/topic/112517-extracting-year-from-date/
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,

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.