Register | Login

Tech Center

Tech Tips

In addition to the ADD_MONTHS function, how can you go to the beginning/end of the month in queries which involve the date field in the WHERE condition?

To retrieve the beginning of nth month from the current date
SELECT ADD_MONTHS(DATE - EXTRACT (DAY FROM DATE) + 1, n)

To retrieve the end of nth month from the current date
SELECT ADD_MONTHS(DATE - EXTRACT (DAY FROM DATE) + 1, (n+1)) - 1

Where n = ...,-3,-2,-1,0,1,2,3,...
   For Last Month n = -1
For Current Month n = 0
   For Next Month n = 1

 

View All Tips >
Got a great idea? Share it with your peers!  >


Company Newsroom Site Help Site Map Privacy/Legal Contact Us