RSS

Great T-SQL Trick: Month And Year From Date

04 Aug

Well, over at one of my favorite forums, Tek-Tips, I was watching a particular thread related to getting the month and year from a particular date. You have to read the whole thing, as the original poster’s issue was quite easy with a bit more SQL background, but the answer supplied by gmmastros – who is pretty much the closest thing to a SQL god I know – was something I would never have thought of. His answer was:

Select Month(GetDate()) * 100 + Year(GetDate()) % 100

Make sure you head on over to the specific thread to read the whole thing.

Advertisements
 
Leave a comment

Posted by on August 4, 2011 in SQL Code

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: