1 在窗体中增加label1 和label2 ,label3caption分别为“住店日期”和“离店日期”,“天数为” 2 在窗体中增加DateTimePicker1和DateTimePicker2分别将其name改为date1 和date2 用于选择两个时间。 3 在窗体中增加两个bitbtn 分别将caption设置为“确定”和“关闭” 4 在label3旁边加一个edit1 用于显示天数。 5 在“关闭”按钮中加 close; 6 在“确定”按钮中加入代码 var z,l,i:Tdatetime; h:string; begin try z:=strtodate(datetostr(date1.Date)); l:=strtodate(datetostr(date2.Date)); i:=l-z; edit1.Text:=floattostr(i); except showmessage('计算失败'); end; end;