计算下月1号与该月1号之间的天数。
function getmonthdays(year,month:integer):Integer;
var
nextmonth : integer;
day1,day2 : date;
begin
if month = 12 then
result := 31
else
beign
nextmonth := month + 1;
day1 := encodeday(year,month,1);
day2 := encodeday(year,nextmonth,1);
Result := Int(day2 - day1);
end;
end;
function getmonthdays(year,month:integer):Integer;
var
nextmonth : integer;
day1,day2 : date;
begin
if month = 12 then
result := 31
else
beign
nextmonth := month + 1;
day1 := encodeday(year,month,1);
day2 := encodeday(year,nextmonth,1);
Result := Int(day2 - day1);
end;
end;
解决方案 »
- delphi的 cardinal返回值类型
- odbc配置问题.
- 高手黑%客:网站攻防,月薪过1W
- 菜单与按钮关联ActionList后,菜单和按钮都变成灰色了.是什么回事.
- 报表问题
- 问一个基础问题
- 如何让label换行?
- 如何安装控件TDosMove?加急!!!!!谢谢各个大哥!!!!!
- 我要跳楼了,救救我,为什么我的JPEG文件装入数据库,再用TADOBlobStream读出来的时候字节多了出来,我再用TJPEGImage 读的时候说 Jpeg error #52 怎么办?我有许多图片要装入数据库里呢?我一定给分
- 一个菜鸟问题!!!
- 在quickrep中统计本月纪录的合计,然后打印。
- mynumcn:=QRExpr2.Caption; ,我想得到QRExpr2中的计算的结果,而不是表达式?
MaxDays:array [1..12] of integer;
MaxDays[1]:=31;MaxDays[2]:=28 .........MaxDays[11]:=30;MaxDays[12]:=31;
然后判断某年是否是闰年,规则如下:
if ((year mod 400=0) or ((year mod 4=0) and (year mod 100<>0)) then
begin
MaxDays[2]:=29;//如果是闰年,将2月份变为29天
end;
如后就可以根据数组得出某月的最大天数.
快快给分!!!!!!!
function DayMax(DateA:TDateTime):TDateTime;stdcall;
const kk:array[1..12] of Integer=
(31,28,31,30,31,30,31,31,30,31,30,31);
var Year,month,day:Word;
begin
DecodeDate(DateA,Year,Month,Day);
if (((Year Mod 4)=0 ) and ((Year Mod 100)<>0)) or
((Year Mod 400)=0) then kk[2]:=29 else kk[2]:=28;
Result:=EncodeDate(Year,Month,kk[Month])
end;
如:要求6月份的天数,用7.1-1得6.30,然后再取day即得30
简单,如下:MonthDays[IsLeapYear(年份), 月份];在SysUtils单元中.
设定一个字符中:
var tdate:string ;
month:integer;
maxdate:string;
begin
TDATE= '312831303130313130313030'
maxdate=copy(tdate,(month*2-1),2)
end ;
是不是可行?????
1,3,5,7,8,10,12:day := 31;
4,6,9,11: day:=30;
2: if year mod 4=0 then Day := 29 else Day:=28;也可以得出!办法是很多的,关键不在于去学别人怎么做;而在于去创造怎么做!!
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Spin;type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
SpinEdit1: TSpinEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
day=28..31;
month=(jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec);
year=1900..2004;
var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var days:day;
months:month;
years:year;
leep:boolean;
begin
years:=spinedit1.value;
edit1.text:='你选择了'+inttostr(spinedit1.value);
if (years mod 400=0)or(years mod 4=0)and(years mod 100<>0) then
leep:=true;
memo1.lines.add(inttostr(spinedit1.value));
memo1.Lines.add('****years****');
for months:=jan to dec do
begin
case months of
jan,mar,may,jul,aug,oct,dec:days:=31;
apr,jun,sep,nov:days:=30;
feb:if leep then
days:=29
else
days:=28;
end;
case months of
jan:memo1.Lines.add('一月'+' '+inttostr(days)+'天');
feb:memo1.Lines.add('二月'+' '+inttostr(days)+'天');
mar:memo1.Lines.add('三月'+' '+inttostr(days)+'天');
apr:memo1.Lines.add('四月'+' '+inttostr(days)+'天');
may:memo1.Lines.add('五月'+' '+inttostr(days)+'天');
jun:memo1.Lines.add('六月'+' '+inttostr(days)+'天');
jul:memo1.Lines.add('七月'+' '+inttostr(days)+'天');
aug:memo1.Lines.add('八月'+' '+inttostr(days)+'天');
sep:memo1.Lines.add('九月'+' '+inttostr(days)+'天');
oct:memo1.Lines.add('十月'+' '+inttostr(days)+'天');
nov:memo1.Lines.add('十一月'+' '+inttostr(days)+'天');
dec:memo1.Lines.add('十二月'+' '+inttostr(days)+'天'+#13#10);
end;
end;end;end.