Thursday, 12 July 2012

Get month and year from a datetime in SQL

Today's Learning:

How to get the current Date and Time in SQL
  Use follwoing SELECT command in SQL

SELECT GETDATE() AS DATE.

Below is output

How to get the MONTH value from GETDATE()
   Use following SELECT command in SQL

SELECT DATEPART (MONTH,GETDATE()) AS MONTH

Below is output

How to get the YEAR value from GETDATE()
   Use following SELECT command in SQL

SELECT DATEPART (YEAR,GETDATE()) AS YEAR

Below is output

No comments:

Post a Comment