T-SQL Tuesday in Local Time

The January edition of T-SQL Tuesday is next week! If you knew that, then you probably already know that the start and end times for T-SQL Tuesday are always at midnight UTC time, and that finding the current UTC date in SQL is as simple as using the GETUTCDATE() function.

SELECT GETUTCDATE();

You can obviously compare the two, but for any T-SQL Tuesday, the questions I really want answered are: “When does it start (in local time)?” and “How much time do I have before it starts and until it ends?” The script below will answer those questions.

This script runs for the current month, and assumes that T-SQL Tuesday is on the second Tuesday of the month (which it *usually* is). And for obvious reasons, it will only work on SQL 2008 and later.

Just now, running it now on my machine gave the following output:

Local time now: Jan 5 2012 8:09AM
The start of T-SQL Tuesday for this month is Jan 9 2012 6:00PM and the end is Jan 10 2012 6:00PM local time.
You have 4 days, 9 hours, 50 mins, and 53 seconds before it starts. Better get moving!

Confession: I really did this as an excuse to learn about some of the new date functionality in SQL 2008+ that I haven’t had a chance to use yet like DATETIMEOFFSET datatype and the SYSDATETIMEOFFSET() funciton, but hopefully it’s helpful as well.