We help IT Professionals succeed at work.

search year in date field

beridius
beridius asked
on
Medium Priority
684 Views
Last Modified: 2012-05-12
i need some code to search the year in a date field it has yyyy-dd-mm
I only need to search year
Comment
Watch Question

Top Expert 2011
Commented:
Are you looking for all records containing a specific year?

SELECT *
FROM table
WHERE date BETWEEN "1990/01/01" AND "1990/12/31"

or are you wanting to query all records and display only the year?

SELECT LEFT(CONVERT(VARCHAR, date, 120), 4)
FROM table
the column is which has  yyyy-dd-mm

1. if  the  column's type is date:
            select  year(column) from table.
2. if the  column's type is varchar or char:
              select  left(column,4) from table.

best regrads.
SAMIR BHOGAYTATeam Lead
CERTIFIED EXPERT

Commented:
Hello,

Select year(column) from table
SELECT datecolumn
FROM table
where year(datecolumn) = '2011';

Explore More ContentExplore courses, solutions, and other research materials related to this topic.