sql query

Database
m_a
New Member

sql query

I want to write query using functions in teradata for

using todays date find 1st day of last month and last day of last month.

3 REPLIES
Senior Apprentice

Re: sql query

SELECT LAST_DAY(ADD_MONTHS(DATE,-1)) AS last_day_prev_month
   ,(LAST_DAY(ADD_MONTHS(DATE,-2))+1) AS first_day_prev_month;

Cheers,

Dave

 

 

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com
Enthusiast

Re: sql query

you can try this too:

 

SELECT DATE,
ADD_MONTHS (DATE, -1) - EXTRACT ( DAY FROM DATE)+1 AS last_month_1st_d,
DATE - EXTRACT ( DAY FROM DATE) AS last_mth_last_day

Junior Contributor

Re: sql query

Another one for the 1st of month:

Trunc(Add_Months(Current_Date,-1), 'mon')