function emontocmon():string; var xmonth:string; year,month,day:word; xdate:tdate; begin xdate:=datetimepicker1.date; decodedate(xdate,year,month,day); case month of 1:xmonth='4月份'; ... 12:xmonth='12月份'; end; result:=xmonth; end;
uses DateUtils;procedure TForm1.Button1Click(Sender: TObject); var I: Integer; begin Memo1.Clear; for I := MonthOf(StrToDate('2002-04-01')) to MonthOf(StrToDate('2002-08-09')) do Memo1.Lines.Add(Format('%d月份', [I])); end;
截出MM
确定区间
var xmonth:string;
year,month,day:word;
xdate:tdate;
begin
xdate:=datetimepicker1.date;
decodedate(xdate,year,month,day);
case month of
1:xmonth='4月份';
...
12:xmonth='12月份';
end;
result:=xmonth;
end;
DateUtils;procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
Memo1.Clear;
for I := MonthOf(StrToDate('2002-04-01')) to MonthOf(StrToDate('2002-08-09')) do
Memo1.Lines.Add(Format('%d月份', [I]));
end;
Yearof(Tdatetime)
Dayof(Tdatetime)
weekof(Tdatetime)
decodedate(a,y,m1,d);
decodedate(b,y,m2,d);
for i := m1 to m2 do s := s := inttostr(i) + '月'#13;
showmessage(s);
如要去掉月份前面的0则改成: IntToStr(StrToInt(Copy(a,6,2)))+'月份'
你可以使用EncodeDate把录入的转换为日期型(也许录入时
就已经是日期型的),然后使用FormatDatetime函数转化格
式为'yyyy-mm-dd',按照楼上的做法补全中间的月份就行了。