Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Add months to date using SQL
Wed, Mar 1 2006 8:44 PMPermanent Link

"Halim Boumedjirek"
How can I add a certain number of months to a timesatmp field and  use it
inside my query :
select * from mytable where mytable.BusinessDate + 28 months <"2006-06-01"

thanks,
-Halim

Wed, Mar 1 2006 9:34 PMPermanent Link

Jeff Cook
"Halim Boumedjirek" <Hboumedjirek@idealss.com> wrote on Wed, 1 Mar 2006 19:43:32 -0600

>How can I add a certain number of months to a timesatmp field and use it
>inside my query :
>select * from mytable where mytable.BusinessDate + 28 months <"2006-06-01"
>
>thanks,
>-Halim
>
>
Halim


I don't know if you can, but why not subtract the months from the date on the right of the < instead - presumably you had to make this date in code anyway.

Something like:-

YourDate := ..... ;
YourMonths := ....;
with Query1 do
begin
   SQL.Text := 'select * from mytable where mytable.BusinessDate< :TestDate';
   ParamByName('TestDate').AsDateTime := IncMonth(YourDate, -YourMonths);
   Open;
end;

HTH

Cheers

Jeff

--
Jeff Cook
Aspect Systems Ltd
Phone: +64-9-424 5388
Skype: jeffcooknz
www.aspect.co.nz



Thu, Mar 2 2006 9:26 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Halim,

<< How can I add a certain number of months to a timesatmp field and  use it
inside my query :  select * from mytable where mytable.BusinessDate + 28
months <"2006-06-01" >>

Do you simply want to increment the month portion of the date by 28 ?  Or do
you want to add approximately (30*28) days ?

--
Tim Young
Elevate Software
www.elevatesoft.com

Thu, Mar 2 2006 1:22 PMPermanent Link

"Halim Boumedjirek"
Yes, I want to increment the month portion by 28 months.

"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote in message
news:20DBB8F7-B584-4A6C-84B0-C2FCFA43A5CA@news.elevatesoft.com...
> Halim,
>
> << How can I add a certain number of months to a timesatmp field and  use
> it inside my query :  select * from mytable where mytable.BusinessDate +
> 28 months <"2006-06-01" >>
>
> Do you simply want to increment the month portion of the date by 28 ?  Or
> do you want to add approximately (30*28) days ?
>
> --
> Tim Young
> Elevate Software
> www.elevatesoft.com
>
>

Fri, Mar 3 2006 10:12 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Halim,

<< Yes, I want to increment the month portion by 28 months. >>

Sorry about that, I didn't realize that you were incrementing the months by
more than a year.  You're going to have to To do so, I would recommend using
a parameter or a constant like this:

select *
from mytable
where mytable.BusinessDate <  :DateParam

where the :DateParam is populated with the desired date - 28 months.  Or you
could just use a constant that you put directly into the SQL text.

--
Tim Young
Elevate Software
www.elevatesoft.com

Fri, Mar 3 2006 12:39 PMPermanent Link

"Halim Boumedjirek"
I went ahead and used IncMonth function. I used it as a constant in the SQL
script.
Thanks to all,
-Halim

"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote in message
news:5AB80C56-595F-4C2B-B250-ABA68BADB206@news.elevatesoft.com...
> Halim,
>
> << Yes, I want to increment the month portion by 28 months. >>
>
> Sorry about that, I didn't realize that you were incrementing the months
> by more than a year.  You're going to have to To do so, I would recommend
> using a parameter or a constant like this:
>
> select *
> from mytable
> where mytable.BusinessDate <  :DateParam
>
> where the :DateParam is populated with the desired date - 28 months.  Or
> you could just use a constant that you put directly into the SQL text.
>
> --
> Tim Young
> Elevate Software
> www.elevatesoft.com
>
>

Image