Reputation: 60
I'm trying to filter my SQL results for a date on a specific year.
The dates are stored in a single column DATE in the format month/day/year
I need to only grab the result for certain years.
String sql = SELECT DATE FROM TABLENAME
WHERE **LAST TWO DATE DIGITS** = ? ORDER BY DATE DESC;
ps.setString(1, yearDesired);
Is this possible? I have been looking around and haven't found an issue directly related to this.
Thank you for any help.
Upvotes: 0
Views: 1775
Reputation: 85126
This should work for SQL Server:
SELECT * FROM TableName where DatePart(YY, myDateColumn) = 2013
Upvotes: 0
Reputation: 238296
Several databases support the YEAR()
function:
WHERE YEAR(dtColumn) between 2003 and 2005
For a more specific answer, post the database you're using.
Upvotes: 1
Reputation: 11733
Most SQL implementations have date functions, e.g. YEAR(DATE) would return the 4 digit year.
Upvotes: 0