Getting the current date and time with Transact-SQL
Recently I was looking for a way to get the current date and time through an SQL query in MS SQL Server 2005. I know that I can do that with the function now() in MySQL and PostgreSQL, but I couldn’t find this function for MS SQL. After digging around I found Matt Faus’s blog which had a post that wrote about the thing I wanted.
Matt Faus’s blog: MS SQL Server Transact-SQL NOW() Function
So to get the current datetime use:
SELECT GETDATE(); GO
Link to the MSDN article (SQL Server 2008): http://msdn2.microsoft.com/en-us/library/ms188383.aspx
Link to the MSDN article (SQL Server 2005): http://msdn.microsoft.com/en-us/library/ms188383(SQL.90).aspx
Also there is a function CURRENT_TIMESTAMP(). Usage is:
SELECT CURRENT_TIMESTAMP(); GO













