Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to only get Year as part of date / datetime in SQL Server

When I create a date type in SQL, the result will come out like this 2012-2-1 Monday 00:00:00

However, I only want the year.

How can I get this?

like image 300
牛さん Avatar asked Dec 12 '22 23:12

牛さん


2 Answers

Make an numeric field with just the year, or use the YEAR() function.

like image 100
Bart Friederichs Avatar answered Feb 23 '23 01:02

Bart Friederichs


datetime, includes date and time, "date" just includes date formats.

select datepart(year,getdate())
like image 34
levi Avatar answered Feb 23 '23 00:02

levi