sudoJustin
sudoJustin

Reputation: 60

SQL Search for substring date

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

Answers (3)

Abe Miessler
Abe Miessler

Reputation: 85126

This should work for SQL Server:

SELECT * FROM TableName where DatePart(YY, myDateColumn) = 2013

Upvotes: 0

Andomar
Andomar

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

Rob
Rob

Reputation: 11733

Most SQL implementations have date functions, e.g. YEAR(DATE) would return the 4 digit year.

SQL Date Functions

Upvotes: 0

Related Questions