Board index » delphi » Adding a Week to a Date

Adding a Week to a Date

Is there a function in Delphi 3 for Incrementing a date by a Week?  There is
a function IncMonth() that will increment by a month, but I can't find one
to Increment by a Week.

I realize I could write a function that would split out the elements of a
date, add 7 to the days, and account for month and year changes, but I'm
looking for an easy way out :)

Any help is appreciated.

Jesse

 

Re:Adding a Week to a Date


Quote
Jesse Castleberry wrote in message <6jdmdu$r9...@news4.ispnews.com>...
>Is there a function in Delphi 3 for Incrementing a date by a Week?  There
is
>a function IncMonth() that will increment by a month, but I can't find one
>to Increment by a Week.

>I realize I could write a function that would split out the elements of a
>date, add 7 to the days, and account for month and year changes, but I'm
>looking for an easy way out :)

Jesse:

It's very easy:  If you have a TDateTime value, just add seven to the value
for one week.  If you want to add N weeks, then NewDate := OldDate + 7*N;

You might be interested in the "Date Math" discussion on the bottom of my
"Dates and Times" page that describes over 50 date and time functions
available in Delphi.  Look for "Delphi Math Functions" in my Computer Lab.

efg
_________________________________________
efg's Computer Lab:  http://infomaster.net/external/efg

Earl F. Glynn                 E-Mail:  EarlGl...@att.net
MedTech Research Corporation, Lenexa, KS  USA

Re:Adding a Week to a Date


Quote
"Jesse Castleberry" <D...@iThink.net> wrote:
> Is there a function in Delphi 3 for Incrementing a date by a Week?

Extremely simple (example follows);

function IncWeek (D : TDateTime; Weeks : Byte) : TDateTime;
begin
  Result := D + (7 * Weeks);
end; { IncWeek }

Haven't tried this function, though, but it should work.  The whole
idea is to add 7x (where x is number of weeks) to the date you already
have.

Hope this helps!

--
Tore Aursand - Norway - tor...@sn.no - http://home.sol.no/~toreau/
"A good sermon should have a good beginning and a good ending, and they
 should be as close together as possible." -- George Burns

Other Threads