| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Last Full Three Months?
"Dan" <dan_at_nospam.com> wrote in message
news:fwkne.15$4A3.2097_at_news.uswest.net...
> Hi,
>
> I have sales line item detail like
>
> invoicedate, custid, ordernum
>
> Is there a way using SQL to only return records for the last full three
> months? For example, if today is 2/4/05, I would want records with
> invoicedate between 11/1/04 and 1/31/05.
Try this:
select invoicedate
from sometable
where invoicedate between
dateadd(mm,-3,cast(convert(varchar(8),getdate(),111)+'01' as datetime))
and
dateadd(dd,-1,cast(convert(varchar(8),getdate(),111)+'01' as
datetime))
-- Pete Brown IT Managers & Engineers Falls Creek Australia www.mountainman.com.au/softwareReceived on Thu Jun 02 2005 - 04:17:33 CDT
![]() |
![]() |