From: Himansu on
Hello everyone,

Anyone know how to select records before 6 months?
Basically I have a date field and I need to select records
older than 6 months from the current date. So today is
03/29/10. I would need all the records BEFORE
10/29/09. Let me know what you guys think.

Thanks,
Himansu


From: AlterEgo on
On Mar 29, 2:24 pm, "Himansu" <himansu...(a)hotmail.com> wrote:
> Hello everyone,
>
> Anyone know how to select records before 6 months?
> Basically I have a date field and I need to select records
> older than 6 months from the current date.  So today is
> 03/29/10.  I would need all the records BEFORE
> 10/29/09.  Let me know what you guys think.
>
> Thanks,
> Himansu

SELECT *
FROM YourTable
WHERE YourDateColumn < DATEADD(m, -6, GETDATE())

That will give you exactly what you are asking for, but that is 6
months back from right now to the minute and millisecond. You might
want to only want everything before 6 mos. ago midnight, use this
instead:

WHERE YourDateColumn < SELECT DATEADD(m, -6, CONVERT(VARCHAR(10) ,
GETDATE(), 101))
From: Himansu on
Thanks.

"AlterEgo" <bill.bertovich(a)gmail.com> wrote in message
news:d795e6ec-9fb6-4252-9944-114b6b07c7c4(a)y17g2000yqd.googlegroups.com...
On Mar 29, 2:24 pm, "Himansu" <himansu...(a)hotmail.com> wrote:
> Hello everyone,
>
> Anyone know how to select records before 6 months?
> Basically I have a date field and I need to select records
> older than 6 months from the current date. So today is
> 03/29/10. I would need all the records BEFORE
> 10/29/09. Let me know what you guys think.
>
> Thanks,
> Himansu

SELECT *
FROM YourTable
WHERE YourDateColumn < DATEADD(m, -6, GETDATE())

That will give you exactly what you are asking for, but that is 6
months back from right now to the minute and millisecond. You might
want to only want everything before 6 mos. ago midnight, use this
instead:

WHERE YourDateColumn < SELECT DATEADD(m, -6, CONVERT(VARCHAR(10) ,
GETDATE(), 101))


From: Himansu on
Hi Bill,

Any idea how I can use 2 column dates? Basically take everyone in
DateField1 before 6 months ago or anyone in DateField1 before 6 months ago?

"AlterEgo" <bill.bertovich(a)gmail.com> wrote in message
news:d795e6ec-9fb6-4252-9944-114b6b07c7c4(a)y17g2000yqd.googlegroups.com...
On Mar 29, 2:24 pm, "Himansu" <himansu...(a)hotmail.com> wrote:
> Hello everyone,
>
> Anyone know how to select records before 6 months?
> Basically I have a date field and I need to select records
> older than 6 months from the current date. So today is
> 03/29/10. I would need all the records BEFORE
> 10/29/09. Let me know what you guys think.
>
> Thanks,
> Himansu

SELECT *
FROM YourTable
WHERE YourDateColumn < DATEADD(m, -6, GETDATE())

That will give you exactly what you are asking for, but that is 6
months back from right now to the minute and millisecond. You might
want to only want everything before 6 mos. ago midnight, use this
instead:

WHERE YourDateColumn < SELECT DATEADD(m, -6, CONVERT(VARCHAR(10) ,
GETDATE(), 101))