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.
MySQL displays YEAR values in YYYY format, with a range of 1901 to 2155 , and 0000 . YEAR accepts input values in a variety of formats: As 4-digit strings in the range '1901' to '2155' .
You can specify the format of the dates in your statements using CONVERT and FORMAT. For example: select convert(varchar(max), DateColumn, 13), format(DateColumn, 'dd-MMM-yyyy')
Try
SELECT RIGHT(YEAR(Creation_Date), 2) YY
FROM Asset_Creation
WHERE ...
Sample output:
| YY | ------ | 10 | | 11 | | 13 |
Here is SQLFiddle demo
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