select Year(Creation_Date)
from Asset_Creation
where Creation_Date = @Creation_Date
I am executing this query where I am getting year as 2013 when supplied today's date. I want the query to return only 13 of 2013. How can I achieve that?
Use SQL Server's YEAR() function if you want to get the year part from a date. This function takes only one argument – a date, in one of the date and time or date data types.
There are 2 ways:
select right(year(getdate()),2)
select year(getdate()) % 100
There are more than 2 ways
, 2 of which are:
SELECT RIGHT(YEAR(Creation_Date),2)
FROM Asset_Creation
WHERE Creation_Date = @Creation_Date
SELECT SUBSTRING(YEAR(Creation_Date),3,2)
FROM Asset_Creation
WHERE Creation_Date = @Creation_Date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With