DateTimeCompare (C++)
Description
The following example demonstrates the use of some date-time routines.
Code
TTime time1, time2;
TDate date1, date2;
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
/* 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);
}
void __fastcall TMainForm::btCompareDateClick(TObject *Sender)
{
/* 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)));
}
void __fastcall TMainForm::btCompareTimeClick(TObject *Sender)
{
/* 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)));
}
void __fastcall TMainForm::btGetDateInfoClick(TObject *Sender)
{
/* 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)));
}
void __fastcall TMainForm::btGetTimeInfoClick(TObject *Sender)
{
/* Write information about the time */
Memo1->Lines->Clear();
time1 = StrToTime(edTime1->Text);
Memo1->Lines->Add("Millisecond of the second: " +
FloatToStr(MilliSecondOfTheSecond(time1)));
Memo1->Lines->Add("Millisecond of the minute: " +
FloatToStr(MilliSecondOfTheMinute(time1)));
Memo1->Lines->Add("Millisecond of the hour: " +
FloatToStr(MilliSecondOfTheHour(time1)));
Memo1->Lines->Add("Millisecond of the day: " +
FloatToStr(MilliSecondOfTheDay(time1)));
Memo1->Lines->Add("Millisecond of the month: " +
FloatToStr(MilliSecondOfTheMonth(time1)));
Memo1->Lines->Add("Millisecond of the year: " +
FloatToStr(MilliSecondOfTheYear(time1)));
Memo1->Lines->Add("Second of the minute: " +
FloatToStr(SecondOfTheMinute(time1)));
Memo1->Lines->Add("Second of the hour: " +
FloatToStr(SecondOfTheHour(time1)));
Memo1->Lines->Add("Second of the day: " +
FloatToStr(SecondOfTheDay(time1)));
Memo1->Lines->Add("Second of the month: " +
FloatToStr(SecondOfTheMonth(time1)));
Memo1->Lines->Add("Second of the year: " +
FloatToStr(SecondOfTheYear(time1)));
Memo1->Lines->Add("Minute of the hour: " +
FloatToStr(MinuteOfTheHour(time1)));
Memo1->Lines->Add("Minute of the day: " +
FloatToStr(MinuteOfTheDay(time1)));
Memo1->Lines->Add("Minute of the month: " +
FloatToStr(MinuteOfTheMonth(time1)));
Memo1->Lines->Add("Minute of the Year: " +
FloatToStr(MinuteOfTheYear(time1)));
Memo1->Lines->Add("Hour of the day: " +
FloatToStr(HourOfTheDay(time1)));
Memo1->Lines->Add("Hour of the month: " +
FloatToStr(HourOfTheMonth(time1)));
Memo1->Lines->Add("Hour of the Year: " +
FloatToStr(HourOfTheYear(time1)));
}
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 )