Home » SQL & PL/SQL » SQL & PL/SQL » Determine first day of the quarter
Determine first day of the quarter [message #18642] Fri, 08 February 2002 05:57 Go to next message
mary
Messages: 19
Registered: November 1999
Junior Member
I would like to know how to write a sql statement which can be embedded in pl/sql package to determine the first day of the quarter. eg I want to do some maintenace but I would like to do it every three months. So I need to determine if the begining of the new quarter to do the maintenance... thanks in advance
Re: Determine first day of the quarter [message #18644 is a reply to message #18642] Fri, 08 February 2002 06:26 Go to previous messageGo to next message
Jon
Messages: 483
Registered: May 2001
Senior Member
There are probably more elegant ways of doing it, but if the following returns 'Yes', it is the first day of the quarter:

select decode(trunc(sysdate)-trunc(last_day(sysdate-1)),1,'Yes','No') FirstDayOfQtr
from dual
where to_char(sysdate,'MM') in ('04','07','10','01')
Re: Determine first day of the quarter [message #18651 is a reply to message #18642] Fri, 08 February 2002 12:24 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
How about:

if sysdate = trunc(sysdate, 'q') then
  -- do something
end if;
Re: Determine first day of the quarter [message #18687 is a reply to message #18642] Mon, 11 February 2002 03:51 Go to previous message
Jon
Messages: 483
Registered: May 2001
Senior Member
You win in my book. Very elegant.
Previous Topic: How to select "last but one row" from a table?????
Next Topic: sp1.msb
Goto Forum:
  


Current Time: Thu Aug 06 02:58:59 CDT 2020