Need to Calcualate 4 quarters from a given date

  • Hi!

    I am working on a report and trying to calculate the previous 4 quarters from a given date. I need help! I am using Teradta SQL.

    Thanks.

  • the trick is to use the datediff and date add functions

    for example here's how to find the first day of "this" quarter, ,and the previous 4 quarters based on today:

    --First Day of the Quarter

    select DATEADD(qq, DATEDIFF(qq,0,getdate()), 0)

    --First Day of Previous Quarter

    select DATEADD(qq, DATEDIFF(qq,0,DATEADD(qq,-1,getdate())), 0)

    --First Day of two quarters ago

    select DATEADD(qq, DATEDIFF(qq,0,DATEADD(qq,-2,getdate())), 0)

    --First Day of three quarters ago

    select DATEADD(qq, DATEDIFF(qq,0,DATEADD(qq,-3,getdate())), 0)

    --First Day of four quarters ago

    select DATEADD(qq, DATEDIFF(qq,0,DATEADD(qq,-4,getdate())), 0)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • shilpa726 (10/14/2009)


    Hi!

    I am working on a report and trying to calculate the previous 4 quarters from a given date. I need help! I am using Teradta SQL.

    Thanks.

    This forum is for questions about Microsoft SQL Server TSQL, not Teradata SQL.

    It is not likely that that date manipulation functions from TSQL will work in Teradata SQL.

    You should ask your questions on a Teradata site.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply