TDateTime

GetDateRecordFromDate

function GetDateRecordFromDate(aDate: TDateTime): TDateRecord;
begin
DecodeDate(aDate, Result.Year, Result.Month, Result.Day);
end;

ClearDatePart

function ClearDatePart(aDateTime: TDateTime): TDateTime;
Var h, m, s, ms: Word;
begin
DecodeTime(aDateTime, h, m, s, ms);
Result := EncodeTime(h, m, s, ms);
end;

ClearTimePart

function ClearTimePart(aDateTime: TDateTime): TDateTime;
Var y, m, d: Word;
begin
DecodeDate(aDateTime, y, m, d);
Result := EncodeDate(y, m, d);
end;

Fungsi Tanggal

Uses SysUtils;
Type TDateRecord = record Year : Word; Month : Word; Day : Word;
end;

Jumlah Hari dalam Satu Bulan

var DaysInYear: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
Days, Month, Year: Word;

implementation …
procedure TForm1.Button1Click(Sender: TObject);
begin
Month:=StrToInt(Edit1.Text);
Year:=StrToInt(Edit2.Text);
if (IsLeapYear(Year)=True)and(Month=2) then
Days:=DaysInYear[Month]+1
else
Days:=DaysInYear[Month];
Label1.Caption:=IntToStr(Days)+’ days in ‘+Edit2.text+’ year’;
end;

procedure TForm1.FormCreate(Sender: TObject);
var Present: TDateTime;
begin
Present:=Now; DecodeDate(Present, Year, Month, Days);
Edit1.Text:=IntToStr(Month);
Edit2.Text:=IntToStr(Year);
end;

Membuat Timer

var MyTime: TDateTime; …
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Interval:=1000;
MyTime:=Now; Timer1Timer(Timer1);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption:=TimeToStr(Now-MyTime);
end;

MonthsPassed

function MonthsPassed(aFrom, anUntil: TDateTime): Integer;
begin
Result := 12 * (YearFromDate(anUntil) – YearFromDate(aFrom)) + MonthFromDate(anUntil) – MonthFromDate(aFrom);
end;

AddMonthsToDate

function AddMonthsToDate(aDate: TDateTime; aNrMonths: Integer): TDateTime;
begin
Result := IncMonth(aDate, aNrMonths);
end;

GetLastDateOfMonth

function GetLastDateOfMonth(aYear, aMonth: Integer): TDateTime;
begin
Result := EncodeDate(aYear, aMonth, GetLastDayOfMonth(aYear, aMonth));
end;

GetFirstDateOfMonth

function GetFirstDateOfMonth(aYear, aMonth: Integer): TDateTime;
begin
Result := EncodeDate(aYear, aMonth, 1);
end;

GetLastDateOfYear

function GetLastDateOfYear(aYear: Integer): TDateTime;
begin
Result := EncodeDate(aYear, 12, 31);
end;

GetFirstDateOfYear

function GetFirstDateOfYear(aYear: Integer): TDateTime;
begin
Result := EncodeDate(aYear, 1, 1);
end;

GetLastDayOfMonth

function GetLastDayOfMonth(aYear, aMonth: Integer): Integer;
Const
cDAYSINMONTHS: Array[1..12] Of Integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
begin
Result := cDAYSINMONTHS[aMonth];
If (aMonth = 2) And
IsLeapYear(aYear) Then
Inc(Result);
end;

DayFromDate

function DayFromDate(aDate: TDateTime): Integer;
begin
Result := GetDateRecordFromDate(aDate).Day;
end;

MonthFromDate

function MonthFromDate(aDate: TDateTime): Integer;
begin
Result := GetDateRecordFromDate(aDate).Month;
end;

YearFromDate

function YearFromDate(aDate: TDateTime): Integer;
begin
Result := GetDateRecordFromDate(aDate).Year;
end;

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: