Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 02 Jan 2004 @ 13:48:06 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: ADD_MONTHS
 
From:   Hassinger, Bill

Eric, I was giving a general tool for determining the last day of any month. Which is: go to the first day of the subsequent month, and subtract one day. While Dieter's method may be "simpler" in the event of the last day of last month, you can't use it to find the last day of the current month, or the last day of any month but the last month.

Last day of current month

Find first day of month

'2003-11-30' - (EXTRACT(DAY FROM DATE '2003-11-30')+1)


add one month

Add_Months('2003-11-30' - (EXTRACT(DAY FROM DATE '2003-11-30')+1), 1)


subtract one day

(Add_Months('2003-11-30' - (EXTRACT(DAY FROM DATE '2003-11-30')+1), 1)) -1



Last day of month, 3 months ago

Find first day of month

'2003-11-30' - (EXTRACT(DAY FROM DATE '2003-11-30')+1)

subtract 2 months

Add_Months('2003-11-30' - (EXTRACT(DAY FROM DATE '2003-11-30')+1), -2)

subtract one day

(Add_Months('2003-11-30' - (EXTRACT(DAY FROM DATE '2003-11-30')+1), -2)) -1



Last day of last month

('2003-11-30' - (EXTRACT(DAY FROM DATE '2003-11-30')+1))-1


in this event, the +1 and -1 cancel eaach other out.


I can use this same technique to define a 12 month span ending 3 months ago, which is not possible with the simple form because the number of days in the month 3 ago can have from 28-31 days.



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023