Dec
9
2008

SQL QT #1: SQL Dates, Fiscal Years, and Quarters, oh my!

This is more of a placeholder post, nothing complicated but wrote it today and thought it may be useful for some people learning SQL.

Had an instance today where someone wanted dates in a report in the following format;

Q4 2008

Easy enough!!!

DECLARE @myDate Datetime
SET @myDate = GETDATE() 
SELECT 'Q' + CAST(DATEPART("q", @myDate) AS char(1)) + ' ' + 
       CAST(YEAR(@myDate) AS char(4)) AS FyQuarter

Nothing crazy nor excited, but useful!

Enjoy!

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About me...

I am a software dev specializing in web based application lovin life in So Cal!

Month List