How to get first and last date of the quarter?

How can I get the first and last date of the quarter?

Comments

  • Quarter can mean different things for different people. Have you tried anything?

  • Today is 2015-12-07.  For us the first date of the quarter would be 2015-10-01.

     

    I tried this: 

    select year(sysdate) || '-' || (quarter(sysdate)-1)*3+1 || '-' || '01' 

    result: 2015-10-01

     

    My way was succesful, I was wondering if there is a better way.

  • The last date of the quarter would be 2015-12-31.

     

    I tried this:

    select date(year(date(current_date - EXTRACT(DOQ FROM CURRENT_DATE) + 1) + 100) || '-' || month(date(current_date - EXTRACT(DOQ FROM CURRENT_DATE) + 1) + 100) || '-' || '01') - 1

     

    Result 2015-12-31

     

    Result is successful, but method is a bit convoluted.

  • SELECT ADD_MONTHS(TRUNC( current_date, 'Q'), 3)-1;

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file