Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get year in format YY in SQL Server in asp.net C#

Tags:

sql

sql-server

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?

like image 234
user2998990 Avatar asked Nov 17 '13 04:11

user2998990


People also ask

How do I select year from date in SQL?

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.


2 Answers

There are 2 ways:

select right(year(getdate()),2)
select year(getdate()) % 100
like image 71
Amir Pournasserian Avatar answered Nov 01 '22 10:11

Amir Pournasserian


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
like image 38
Hanky Panky Avatar answered Nov 01 '22 11:11

Hanky Panky