Transact SQL Other Articles Software Reviews
SQL Server Help: Find the current date in Microsoft's Transact SQL
Getting the current date (and/or time) in SQL Server's SQL is easy - just use the GetDate function. This can be used to show the current date:
SELECT GetDate() AS 'CurrentDate'
The GetDate function can also be used to assign the current date to a datetime variable, as shown in the following example:
DECLARE @TodaysDate DATETIME
Note that to determine just the year, month, day, week or time from the current date, the DatePart function can be used, for example:
This query is used to get the Year of today's date in SQL. Similar functions are called Day and Month. The year is retrieved as an int data type, so if you want to use it in a string it has to be converted to a char or varchar data type.