Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL current year

 
M Wilson
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on your database.
On Oracle there is TO_DATE conversion function, on MySQL - STR_TO_DATE function.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic