Getting the current date and time with Transact-SQL

2009 January 19
by horgasz

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

Docs for this (SQL Server 2005)

Twit This Post!

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to Ma.gnoliaAdd to TechnoratiAdd to FurlAdd to Newsvine

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS