DateTimeCompare (Delphi)
Description
The following example demonstrates the use of some date-time routines.
Code
var
time1, time2: TTime;
date1, date2: TDate;
procedure TMainForm.btCompareDateClick(Sender: TObject);
begin
{ Compare the two dates }
Memo1.Lines.Clear;
date1 := StrToDate(edDate1.Text);
date2 := StrToDate(edDate2.Text);
Memo1.Lines.Add(IntToStr(CompareDate(date1, date2)));
Memo1.Lines.Add('Day span: '+ FloatToStr(DaySpan(date1, date2)));
Memo1.Lines.Add('Days between: '+ FloatToStr(DaysBetween(date1, date2)));
Memo1.Lines.Add('Week span: '+ FloatToStr(WeekSpan(date1, date2)));
Memo1.Lines.Add('Weeks between: '+ FloatToStr(WeeksBetween(date1, date2)));
Memo1.Lines.Add('Month span: '+ FloatToStr(MonthSpan(date1, date2)));
Memo1.Lines.Add('Months between: '+ FloatToStr(MonthsBetween(date1, date2)));
Memo1.Lines.Add('Year span: '+ FloatToStr(YearSpan(date1, date2)));
Memo1.Lines.Add('Years between: '+ FloatToStr(YearsBetween(date1, date2)));
end;
procedure TMainForm.btCompareTimeClick(Sender: TObject);
begin
{ Compare the two times }
Memo1.Lines.Clear;
time1 := StrToTime(edTime1.Text);
time2 := StrToTime(edTime2.Text);
Memo1.Lines.Add(IntToStr(CompareTime(time1, time2)));
Memo1.Lines.Add('Hour span: '+ FloatToStr(HourSpan(time1, time2)));
Memo1.Lines.Add('Hours between: '+ FloatToStr(HoursBetween(time1, time2)));
Memo1.Lines.Add('Minute span: '+ FloatToStr(MinuteSpan(time1, time2)));
Memo1.Lines.Add('Minutes between: '+ FloatToStr(MinutesBetween(time1, time2)));
Memo1.Lines.Add('Second span: '+ FloatToStr(SecondSpan(time1, time2)));
Memo1.Lines.Add('Seconds between: '+ FloatToStr(SecondsBetween(time1, time2)));
Memo1.Lines.Add('Millisecond span: '+ FloatToStr(MilliSecondSpan(time1, time2)));
Memo1.Lines.Add('Milliseconds between: '+ FloatToStr(MilliSecondsBetween(time1, time2)));
end;
procedure TMainForm.btGetDateInfoClick(Sender: TObject);
begin
{ Write information about the date }
Memo1.Lines.Clear;
date1 := StrToDate(edDate1.Text);
Memo1.Lines.Add('Day in week: ' + IntToStr(DayOfTheWeek(date1)));
Memo1.Lines.Add('Day in month: ' + IntToStr(DayOfTheMonth(date1)));
Memo1.Lines.Add('Day in year: ' + IntToStr(DayOfTheYear(date1)));
Memo1.Lines.Add('Week of the date: ' + IntToStr(WeekOf(date1)));
Memo1.Lines.Add('Week in month: ' + IntToStr(WeekOfTheMonth(date1)));
Memo1.Lines.Add('Week in year: ' + IntToStr(WeekOfTheYear(date1)));
Memo1.Lines.Add('Month in year: ' + IntToStr(MonthOfTheYear(date1)));
end;
procedure TMainForm.btGetTimeInfoClick(Sender: TObject);
begin
{ Write information about the time }
Memo1.Lines.Clear;
time1 := StrToTime(edTime1.Text);
Memo1.Lines.Add('Millisecond of the second: ' +
IntToStr(MilliSecondOfTheSecond(time1)));
Memo1.Lines.Add('Millisecond of the minute: ' +
IntToStr(MilliSecondOfTheMinute(time1)));
Memo1.Lines.Add('Millisecond of the hour: ' +
IntToStr(MilliSecondOfTheHour(time1)));
Memo1.Lines.Add('Millisecond of the day: ' +
IntToStr(MilliSecondOfTheDay(time1)));
Memo1.Lines.Add('Millisecond of the month: ' +
IntToStr(MilliSecondOfTheMonth(time1)));
Memo1.Lines.Add('Millisecond of the year: ' +
IntToStr(MilliSecondOfTheYear(time1)));
Memo1.Lines.Add('Second of the minute: ' +
IntToStr(SecondOfTheMinute(time1)));
Memo1.Lines.Add('Second of the hour: ' +
IntToStr(SecondOfTheHour(time1)));
Memo1.Lines.Add('Second of the day: ' +
IntToStr(SecondOfTheDay(time1)));
Memo1.Lines.Add('Second of the month: ' +
IntToStr(SecondOfTheMonth(time1)));
Memo1.Lines.Add('Second of the year: ' +
IntToStr(SecondOfTheYear(time1)));
Memo1.Lines.Add('Minute of the hour: ' +
IntToStr(MinuteOfTheHour(time1)));
Memo1.Lines.Add('Minute of the day: ' +
IntToStr(MinuteOfTheDay(time1)));
Memo1.Lines.Add('Minute of the month: ' +
IntToStr(MinuteOfTheMonth(time1)));
Memo1.Lines.Add('Minute of the Year: ' +
IntToStr(MinuteOfTheYear(time1)));
Memo1.Lines.Add('Hour of the day: ' +
IntToStr(HourOfTheDay(time1)));
Memo1.Lines.Add('Hour of the month: ' +
IntToStr(HourOfTheMonth(time1)));
Memo1.Lines.Add('Hour of the Year: ' +
IntToStr(HourOfTheYear(time1)));
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
{ Insert the current time and date in the edit-boxes }
time1 := Time;
time2 := Time;
date1 := Today;
date2 := Tomorrow;
edTime1.Text := TimeToStr(time1);
edTime2.Text := TimeToStr(time2);
edDate1.Text := DateToStr(date1);
edDate2.Text := DateToStr(date2);
end;
Uses
- System.DateUtils.CompareTime ( fr | de | ja )
- System.DateUtils.DayOfTheMonth ( fr | de | ja )
- System.DateUtils.DayOfTheWeek ( fr | de | ja )
- System.DateUtils.DayOfTheYear ( fr | de | ja )
- System.DateUtils.DaysBetween ( fr | de | ja )
- System.DateUtils.DaySpan ( fr | de | ja )
- System.DateUtils.HourOfTheDay ( fr | de | ja )
- System.DateUtils.HourOfTheMonth ( fr | de | ja )
- System.DateUtils.HourOfTheWeek ( fr | de | ja )
- System.DateUtils.HourOfTheYear ( fr | de | ja )
- System.DateUtils.HoursBetween ( fr | de | ja )
- System.DateUtils.HourSpan ( fr | de | ja )
- System.DateUtils.MilliSecondOfTheDay ( fr | de | ja )
- System.DateUtils.MilliSecondOfTheHour ( fr | de | ja )
- System.DateUtils.MilliSecondOfTheMinute ( fr | de | ja )
- System.DateUtils.MilliSecondOfTheMonth ( fr | de | ja )
- System.DateUtils.MilliSecondOfTheSecond ( fr | de | ja )
- System.DateUtils.MilliSecondOfTheWeek ( fr | de | ja )
- System.DateUtils.MilliSecondOfTheYear ( fr | de | ja )
- System.DateUtils.MilliSecondsBetween ( fr | de | ja )
- System.DateUtils.MilliSecondSpan ( fr | de | ja )
- System.DateUtils.MinuteOfTheDay ( fr | de | ja )
- System.DateUtils.MinuteOfTheHour ( fr | de | ja )
- System.DateUtils.MinuteOfTheMonth ( fr | de | ja )
- System.DateUtils.MinuteOfTheWeek ( fr | de | ja )
- System.DateUtils.MinuteOfTheYear ( fr | de | ja )
- System.DateUtils.MinutesBetween ( fr | de | ja )
- System.DateUtils.MinuteSpan ( fr | de | ja )
- System.DateUtils.MonthOfTheYear ( fr | de | ja )
- System.DateUtils.MonthsBetween ( fr | de | ja )
- System.DateUtils.MonthSpan ( fr | de | ja )
- System.DateUtils.SecondOfTheDay ( fr | de | ja )
- System.DateUtils.SecondOfTheHour ( fr | de | ja )
- System.DateUtils.SecondOfTheMinute ( fr | de | ja )
- System.DateUtils.SecondOfTheMonth ( fr | de | ja )
- System.DateUtils.SecondOfTheWeek ( fr | de | ja )
- System.DateUtils.SecondOfTheYear ( fr | de | ja )
- System.DateUtils.SecondsBetween ( fr | de | ja )
- System.DateUtils.SecondSpan ( fr | de | ja )
- System.DateUtils.Tomorrow ( fr | de | ja )
- System.DateUtils.WeekOf ( fr | de | ja )
- System.DateUtils.WeekOfTheMonth ( fr | de | ja )
- System.DateUtils.WeekOfTheYear ( fr | de | ja )
- System.DateUtils.WeeksBetween ( fr | de | ja )
- System.DateUtils.WeekSpan ( fr | de | ja )
- System.DateUtils.YearsBetween ( fr | de | ja )
- System.DateUtils.YearSpan ( fr | de | ja )