Board index » delphi » Help needed with TDateTime

Help needed with TDateTime

Hi there

I need a function that will increase the value in a TDateTime with a
number of months

e.g.

03-05-99 + 1 month --> 03-06-99

23-12-99 + 4 months --> 23-03-00

Is this possible

Thanks in advance

Farouche

 

Re:Help needed with TDateTime


  Take a look at DecodeDate...  --  Then add to the months, and call
EncodeDate...

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are Microsoft.  Resistance is Futile.  You will be assimilated.
--

Quote
Farouche <a...@mail1.stofanet.dk> wrote in message

news:372C63BB.A3137E82@mail1.stofanet.dk...
Quote
> Hi there

> I need a function that will increase the value in a TDateTime with a
> number of months

> e.g.

> 03-05-99 + 1 month --> 03-06-99

> 23-12-99 + 4 months --> 23-03-00

> Is this possible

> Thanks in advance

> Farouche

Re:Help needed with TDateTime


Hi

Won't this be a problem if ypu want to go from e.g. 12-12-99 to 12-04-00.
It won't change the year by this method.

Farouche

Quote
Jason Wallace wrote:
>   Take a look at DecodeDate...  --  Then add to the months, and call
> EncodeDate...

> --
> Jason Wallace
> SL Software
> Dark...@SLSoftware.reno.nv.us
> --
> "We are Microsoft.  Resistance is Futile.  You will be assimilated.
> --

> Farouche <a...@mail1.stofanet.dk> wrote in message
> news:372C63BB.A3137E82@mail1.stofanet.dk...
> > Hi there

> > I need a function that will increase the value in a TDateTime with a
> > number of months

> > e.g.

> > 03-05-99 + 1 month --> 03-06-99

> > 23-12-99 + 4 months --> 23-03-00

> > Is this possible

> > Thanks in advance

> > Farouche

Re:Help needed with TDateTime


In article <372C7CC8.C9BEB...@mail1.stofanet.dk>, Farouche

Quote
<a...@mail1.stofanet.dk> writes:
>Won't this be a problem if ypu want to go from e.g. 12-12-99 to 12-04-00.
>It won't change the year by this method.

  Month := ((Month + 11 + MonthsOn) mod 12) + 1;

 . . . would cope with the year end spanning, but what is three months on from
31 August - is it 30 November or 1 December ?

Once you've decided, then you can write your procedure.

Calender.pas has some useful routines.

Alan Lloyd
alangll...@aol.com

Re:Help needed with TDateTime


  Well, obviously you'd need to write some code to figure out what's what
before encoding the date back...  --  If it's over 12, then take the month,
and div it by 12, add that to the year...

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are Microsoft.  Resistance is Futile.  You will be assimilated.
--

Quote
Farouche <a...@mail1.stofanet.dk> wrote in message

news:372C7CC8.C9BEB2D3@mail1.stofanet.dk...
Quote
> Hi

> Won't this be a problem if ypu want to go from e.g. 12-12-99 to 12-04-00.
> It won't change the year by this method.

> Farouche

> Jason Wallace wrote:

> >   Take a look at DecodeDate...  --  Then add to the months, and call
> > EncodeDate...

> > --
> > Jason Wallace
> > SL Software
> > Dark...@SLSoftware.reno.nv.us
> > --
> > "We are Microsoft.  Resistance is Futile.  You will be assimilated.
> > --

> > Farouche <a...@mail1.stofanet.dk> wrote in message
> > news:372C63BB.A3137E82@mail1.stofanet.dk...
> > > Hi there

> > > I need a function that will increase the value in a TDateTime with a
> > > number of months

> > > e.g.

> > > 03-05-99 + 1 month --> 03-06-99

> > > 23-12-99 + 4 months --> 23-03-00

> > > Is this possible

> > > Thanks in advance

> > > Farouche

Re:Help needed with TDateTime


Quote
On Sun, 02 May 1999 16:39:55 +0200, Farouche <a...@mail1.stofanet.dk> wrote:
>I need a function that will increase the value in a TDateTime with a
>number of months

>e.g.

>03-05-99 + 1 month --> 03-06-99

>23-12-99 + 4 months --> 23-03-00

>Is this possible

See the IncMonth function. IncMonth can be used to either increment or
decrement a TDate or TDateTime value by whole months.

//////////////////////////////////////////////////////////////////////////
Steve Koterski                   "There are two kinds of pedestrians...the
Technical Publications           quick and the dead."
INPRISE Corporation                            -- Lord Thomas Robert Dewar
http://www.borland.com/delphi                                  (1864-1930)

Other Threads