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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the first day of week

Status
Not open for further replies.

filipe26

Programmer
Mar 17, 2003
152
PT
How can i get the first day of the week (type Tdatetime)of a certain date.

Thanks.
 
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  dtSomeDate,dtSunday: TDateTime;
begin
  dtSomeDate := StrToDate(Edit1.Text);
  dtSunday := dtSomeDate - DayOfWeek( dtSomeDate ) + 1;
  Edit2.Text := DateToStr( dtSunday );
end;
 
filipe26,

Depends on what you mean by start of the week. If you're looking for Monday and are using a recent version of Delphi (e.g. 6.0 or later), you can use the StartOfTheWeek function from the DateUtils unit.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top