This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes SQL current year Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL current year" Watch "SQL current year" New topic
Author

SQL current year

M Wilson
Ranch Hand

Joined: May 23, 2010
Posts: 32
select distinct MODEL
from VEH_TABLE
where MAKE = 'Ford'
and VEH_YEAR = YEAR(CURRENT DATE)

I want to get the current year but VEH_YEAR is data type char (string) so the result errors because the data types are incompatible. How do you convert/cast YEAR(CURRENT DATE) to char? I tried, doesn't work cause incorrect?
and VEHICLE_YEAR = CAST (YEAR(CURRENT DATE) CHAR(4))

Thank you very much.
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Depends on your database.
On Oracle there is TO_DATE conversion function, on MySQL - STR_TO_DATE function.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL current year