请问有没有办法,对日期的年月直接进行加减操作?能不能提供一个小例子?(20分)

  • 主题发起人 主题发起人 jianglai
  • 开始时间 开始时间
直接??用转化吧:strtodate()
 
有啊,D6中有,我将D5卸载了。
IncAMonth procedure

Increments date data by one month.

IncDay function

Returns a date shifted by a specified number of days.

IncHour function

Returns a date/time value shifted by a specified number of hours.

IncMilliSecond function

Returns a date/time value shifted by a specified number of milliseconds.

IncMinute function

Returns a date/time value shifted by a specified number of minutes.

IncMonth function

Returns a date shifted by a specified number of months.

IncSecond function

Returns a date/time value shifted by a specified number of seconds.

IncWeek function

Returns a date shifted by a specified number of weeks.

IncYear function

Returns a date shifted by a specified number of years.
 
在Delphi中,tdatetime本身就是基于tfloat的,直接加减就行了
example1:
T:TDateTime;
T:=T+StrToTime('00:00:01');//T加一秒。
T:=T+StrToTime('00:01:00');//T加一分钟。
在SQL中,用dateadd函数
DATEADD(day, 21, pubdate)返回pubdate(datetime)加21天,具体你可以看看query analyzer
中t-sql的帮助
 
TDATTIME在delphi中其实就是一个浮点类型,看一看帮助!
 
两个函数 function EncodeDate(year,month,day:word);
可把三个word型变量转换成一个日期型时间变量;
procedure DecodeDate(date:tdatetime;var year,month,day:word);
可把日期型(####年##月##日)变为三个word型变量.
var date1,date2,date:tdatetime;
year1,year2,month1,month2,day1,day2,year,month,day:word;
程序部分
date1:=encode(year1,month1,day1);
date2:=encode(year2,month2,day2);
date:=date1-date2;
decodedate(date,year,month,day);
edit1.text:='两个日期之间间隔'+inttostr(year-1900)+'年'=inttostr(month)+'月'+inttostr(day)+'日';


 
begindate,enddate:variant;
date_1,date_2:Tdatetime;
days:integer;

begindate:=date_1;
enddate:=date_2;
days:=enddate-begindate;

days就是两个日期的间隔天数了。。:)
 
TDATTIME在delphi中是一个浮点类型
var
t1,t2:Tdatetime;
i:real;
begin
t1:=now;
t2:=now+1; //加一天
i:=t2-t1; //两个日期型相减,相差为 1天
 
D6的函数:
procedure IncAMonth(var Year, Month, Day: Word; NumberOfMonths: Integer = 1);

Description

IncAMonth modifies Year, Month, and Day parameters so the date they describe
is incremented by NumberOfMonths months. NumberOfMonths can be negative,
to return a date N months previous.

If the input day of month is greater than the last day of the resulting month,
the day is set to the last day of the resulting month.
 
后退
顶部