例えば日曜日なら、2003/12/14,2003/12/7,2003/11/30...
といったように特定の曜日の日付を求めるにはどうすればいいでしょうか?
どうぞ、よろしくお願いします。
おもしろそうなので、試しに。。。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Calendar;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Calendar1: TCalendar;
procedure Button1Click(Sender: TObject);
private
{ Private 宣言 }
public
{ Public 宣言 }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure GetHoge(Yobi: Integer; MaxCount: Integer; HizukeList: TStrings);
var
D: TDateTime;
begin
D := Date;
while not (DayOfWeek(D)=Yobi) do D := D-1;
HizukeList.Add(FormatDateTime('yyyy/mm/dd',D));
D := D-7;
Dec(MaxCount);
while MaxCount>0 do begin
HizukeList.Add(FormatDateTime('yyyy/mm/dd',D));
D := D-7;
Dec(MaxCount);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items.Clear;
ListBox1.Items.Add('日曜');
GetHoge(1,10,ListBox1.Items);
ListBox1.Items.Add('土曜');
GetHoge(7,10,ListBox1.Items);
end;
end.
早速のご回答ありがとうございます。
求める内容はこれでばっちりなので、自分のプログラムに応用してみます。
ツイート | ![]() |