Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find the date of the upcomming tesday 2

Status
Not open for further replies.

DelphiAaron

Programmer
Jul 4, 2002
826
AU
does anyone know a eay to get thew date on the next tuesday.

if today is tuesday then return todays date but if today is any other day return its date.

thanx

Aaron
 
Either one of two approaches I can think of:

1. Use an algorithm known as Zeller's Congruence to determine the day of today's date, if it's anything other than Tuesday, then determine the number of days between the current day and Tuesday and add that to today's date and return that date.

2. Use the storage format on the TDateTime type (or whatever "Now" uses = "x days/hours/minutes/seconds from this date") to determine that. You should be able to establish the day of the week that "this date" is, and adjust the number accordingly to establish the date you want to return.

If details are necessary, I can draw up some bits of code for this.
 
The Delphi DateUtils unit provides a useful function DayOfTheWeek which returns the day of the week. Monday is 1, Tuesday 2 and so on. DateUtils also has the constants
Code:
DayMonday = 1;
DayTuesday = 2;
and so on.

Something like the following function should provide you with what you want:
Code:
function NextTuesday( datum: TDate ): TDate;
begin
  case DayOfTheWeek( datum ) of
    DayMonday: result := datum + 1;
    DayTuesday: result := datum;
  else
    result := datum + DayTuesday - DayOfTheWeek( datum ) + 7;
  end;
end;

Andrew
Hampshire, UK
 
thanx guys.
love my typos..

dislexia rules k.o.

Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top