delphi 中对 ‘年-月’进行加减操作 delphi 中对 ‘年-月’进行加减操作,如对字符串型“2007-07”减一个月,有什么函数可以使用。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 uses DateUtils;IncMonth(日期, -1); 看date/time routines里的函数,这里有操作date/time的所有的函数. function IncMonthStr(Dt: string; val: integer): string;begin Result := FormatDatetime('YYYY-MM', IncMonth(StrtoDate(Dt+'-01'), val));end;procedure TForm1.Button3Click(Sender: TObject); {测试}var S1, S2: string;begin S1 := '2007-01'; S2 := IncMonthStr(S1, -1); Showmessage(S2);end; 转日期然后用IncMonth()加减 {多种测试}{但并不是通用函数,因为还没有考虑系统日期设置的分隔符问题,自己控制使用而已}function IncMonthStr(Dt: string; val: integer): string;begin Result := FormatDatetime('YYYY-MM', IncMonth(StrtoDate(Dt+'-01'), val));end;procedure TForm1.Button1Click(Sender: TObject);var S1, S2: string;begin S1 := '2007-01'; S2 := IncMonthStr(S1, -1); //减1个月 Showmessage(S2); S2 := IncMonthStr(S1, 2); //加2个月 Showmessage(S2); S2 := IncMonthStr(S1, 13); //加13个月 Showmessage(S2); S2 := IncMonthStr(S1, -6); //减6个月 Showmessage(S2);end; 大量数据删除,有近百万条,有什么办法最快? 如何调用这样的DLL 程序退出的时候报runtime error 217 at......什么原因? 字符串问题!问题不难,在线等,一解决马上结贴! 请问,如何在程序中将InterBase中的数据以文件形式导出????100分相送 DLL问题? 关于用Delphi实现Ping功能的问题 在Delphi中如何获得网卡的MAC地址? 请教,怎样对数据查询? 请问如何得知,一个局域网上是否有两个ip相同,而且网卡地址也相同的计算机存在? 关于SLEEP()函数的理解 重新加载程序
begin
Result := FormatDatetime('YYYY-MM', IncMonth(StrtoDate(Dt+'-01'), val));
end;procedure TForm1.Button3Click(Sender: TObject); {测试}
var
S1, S2: string;
begin
S1 := '2007-01';
S2 := IncMonthStr(S1, -1);
Showmessage(S2);
end;
IncMonth()加减
begin
Result := FormatDatetime('YYYY-MM', IncMonth(StrtoDate(Dt+'-01'), val));
end;procedure TForm1.Button1Click(Sender: TObject);
var
S1, S2: string;
begin
S1 := '2007-01';
S2 := IncMonthStr(S1, -1); //减1个月
Showmessage(S2); S2 := IncMonthStr(S1, 2); //加2个月
Showmessage(S2); S2 := IncMonthStr(S1, 13); //加13个月
Showmessage(S2); S2 := IncMonthStr(S1, -6); //减6个月
Showmessage(S2);
end;