���������� ���� ������!

����� ������:

Programming articles

�������� ������ �� ��������

��������� ��������� ������ � �������� �� �����

������� ���� � ������� ������� �����

�������� API ������� - ������

��� ������� ������������� ������� ����

�������� ��������� ������� � Delphi 7

���������� ������� ��� ������� �������������� �����

���������� windows � ������� Delphi

�������� wap �����

������������ ������� unix, ������� � �������

SQL ���� ��� ����

������������� � ������ �������� �� UNIX

����������� ������� � Delphi

�������, ����� ����� �������

������� ������������� 20 ����

������ �� �������� ������������ ����� � ����

������� ���� � ������� ������

�������� - ��������� �������

Crypt - Delphi ��������� ��� ����������

��������, ����� ��� ����� � ��� �� ������������?

������� �� C++ ��� ���������� �������������

����� ��� �������� ����������

���������� ��� PCHAR

�������� �� �������� ������

��������� �������������� ������� is � as

Borland Developer studio 2006. �� � �����

�������� ���� ������ � Delphi, ��� ��������� ��


Software engineering articles



Date time � Delphi

������������� ������� ������ � �����/��������

    ���� ���������������� Borland Delphi � ����� ������� �������� �������� ���������� ������� ��� ������ � ����� ������ TDateTime (���������� �������� BorlandDelphi ����������� ���������� ������ ����/�����) , ����������� ����������� ����������� ����� ����������� � �������������� ������ ������. ������, ��� ���� ���� �������� ��������� ������ �������� ����� �������������� ������� ����� �������� �������� �������� �������� ������������ ��� ��������� ����������� ���� �� ������� ����������. ����, ����-�� ���������, �� ��������� ��� �����������, ��� ���������� � �������� � ��������� ���� ������.

������ ������:

    ���, ���������� ���� �� ������ ���� ���� �� ������? ���������� ����� �� ���� ������, ����� ������ ������, � ��� ��� ������ Delphi?

     23.01.07- 21.11.06= 03.03.1900 �����, �� � � ��� �� �� ��� �� ����, ���� ������. �������������� ��������� ���������� ����� ��������, �������� ����� ��������.
23.01.07 -
21.11.06
-------------
2

    ����� 2 ������ 2 ���. ��� ������ ���������� ��� ���������� ���� � ������ (12 �������). ��� ���� �������� � ��������� �������. ����� �������� �� ������, ��� � ���� � ��� 360 ���� (12 ������� �� 30 ����), ���, ��-�����, ��� �� Excel �������. �������� ����� ������� �� ���������� ���� �� ��� ������ � ����, � ����������, ��, ��� ���� ��������, � ����� �� ������ � ���� ������.

function Period(BeginDate, EndDate: Tdatetime): string;
var
SubDate:Tdatetime;
md,mm,my:integer;
begin
SubDate:=EndDate-BeginDate;
md:=dayof(EndDate)-dayof(begindate);
mm:=monthof(EndDate)-monthof(begindate);
my:=yearof(EndDate)-yearof(begindate);
if md<0 then begin
         md:=md+30;
         mm:=mm-1;
         end;
if mm<0 then begin
         my:=my-1;
         mm:=mm+12;
         end;
Period:=inttostr(md)+'.'+inttostr(mm)+'.'+inttostr(my);
end;

    ��� ����� ������� �� ������� ������ ������.

������ ������:

    ��� �� ������? ������ �� ��������, � ������ ���� ������� �������, ��� �� �� ���������� ����, ���������� TDateTime'� �� �� ������. � ����� ������� �������, ������� ������ ��� ��� ����, ���������� � ������� �������.

function SummaPeriod(BeginDate, EndDate: string): string;
var
bd,bm,by:integer;
ed,em,ey:integer;
sd,sm,sy:integer;
begin
randomize;
bd:=dayof(strtodate(BeginDate));
bm:=monthof(strtodate(BeginDate));
by:=yearof(strtodate(BeginDate))-2000;
ed:=dayof(strtodate(EndDate));
em:=monthof(strtodate(EndDate));
ey:=yearof(strtodate(EndDate))-2000;
sd:=bd+ed;
sm:=bm+em;
sy:=by+ey;
if sd>=30 then
         begin
         sd:=sd-30;
         sm:=sm+1;
         end;
if sm>=12 then
         begin
         sm:=sm-12;
         sy:=sy+1;
         end;
SummaPeriod:=inttostr(sd)+'.'+inttostr(sm)+'.'+inttostr(sy);
end;

     ����� �������� ��� ������, � ��� ��� �� �����? by:=yearof(strtodate(BeginDate))-2000; �� ������ ��������� ������ � �������� ��, �� �����.

������ ������:

     ������� ������ ������, ��������� ����� ����������� ���� TdateTime (������ ������� � ����� �������) ��������� ���������� ������ ��������� ���� � ���� ��������. ��������� �����������, ������ �����, � ���, ��� ���������� ������� ��� TdateTime ��� �������� ����. ���, ��������, � ������ 23 �������, 8 �����, ����� ��� (����� ������� ��������). ��� �������� ������� "������� ���� ���������" ����� ������������ ��� String. �������, ������� ���������� ��������� ���� � �������� ��������, ���������� �������� �����:

function Holydays(BeginDate, EndDate: Tdatetime;holyday: string): integer;
var
output:integer;
md:string;
begin
md:=holyday+'.'+inttostr(yearof(EndDate));
if (CompareDateTime(strtodate(md), EndDate)<=0) and
     (CompareDateTime(BeginDate,strtodate(md))<=0)then
         begin
         output:=1;
         end else output:=0;
if output=0 then
       begin
md:=holyday+'.'+inttostr(yearof(BeginDate));
if (CompareDateTime(strtodate(md), EndDate)<=0) and
       (CompareDateTime(BeginDate,strtodate(md))<=0)then
         begin
         output:=1;
         end else output:=0;
         end;
Holydays:=output;
end;

    ���� � ���������� ���������� ���������� "1", �� ���� � �������� �������� ������, � ��������� ������ ���.
    ���������� �������� �������� ������ ������� �����������. BeginDate - ������ �������, EndDate - ��������� �������, holyday - ���������� �������� (� ������� "23.02") md:=holyday+'.'+inttostr(yearof(EndDate)); - �������� ���� ��������� � ������������ � ����� TDateTime �������� ���� ������� �� ��������� ������� (��� ������, ����� ������ �������, ���� � ����� ����, � ��������� ��� � ������). ����� ���� �������� �������� �� ��������� � �������� ��������:

if (CompareDateTime(strtodate(md), EndDate)<=0) and
      (CompareDateTime(BeginDate,strtodate(md))<=0)then
         begin
         output:=1;
         end else output:=0;

    ��, �� ��� ��� ������ ��� ����� ����������, � ������ � �������� ������� ���� ������ �������- 27.11.06, ��������� ������� - 10.01.07, �������� 29.11 (������������ ������, �� � ��� � ����� ������ ������), � ������ �� �������� ���� � ������������ md:=holyday+'.'+inttostr(yearof(BeginDate)); � ��������! ��� ����� �������� �������������� ������� ����������. ������ ����� ��������� ���� ������ ������� ���������� � �������� �� �� ������� ����������. -- � ���������, ����� mailto:AntonCH82@mail.ru

�������� �� ������




Warning: require_once(/home/program/programmersclub.ru/docs/60c3403e55019aa8da82c567fcf8afa0/sape.php): failed to open stream: No such file or directory in /home/program/programmersclub.ru/docs/datetimeanton/index.php on line 868

Fatal error: require_once(): Failed opening required '/home/program/programmersclub.ru/docs/60c3403e55019aa8da82c567fcf8afa0/sape.php' (include_path='.:/home/program/programmersclub.ru/php') in /home/program/programmersclub.ru/docs/datetimeanton/index.php on line 868