DateUtils (C++)
From RAD Studio Code Examples
Language:
Description
This example demonstrates the use of some routines included in the DateUtils unit. The form contains a TDateTimePicker and several TEdit boxes, used for rereading and writing elements of a TDateTime object.
Code
__fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner) { DateTimePicker1->Format = "dd/MM/yyyy hh:mm"; /* Get the current date and time */ DateTimePicker1->Date = Date(); DateTimePicker1->Time = Time(); /* Write the current date in the first edit-box */ edFirstDate->Text = DateToStr(Today()); /* Write the previous date in the second edit-box */ edSecondDate->Text = DateToStr(Yesterday()); } //--------------------------------------------------------------------------- void __fastcall TMainForm::btGetInfoClick(TObject *Sender) { /* Get the day from the selected date */ edDay->Text = IntToStr(DayOf(DateTimePicker1->Date)); /* Get the moonth from the selected date */ edMonth->Text = IntToStr(MonthOf(DateTimePicker1->Date)); /* Get the year from the selected date */ edYear->Text = IntToStr(YearOf(DateTimePicker1->Date)); /* Get the hour from the selected date */ edHour->Text = IntToStr(HourOf(TimeOf(DateTimePicker1->Time))); /* Get the minute from the selected date */ edMinute->Text = IntToStr(MinuteOf(TimeOf(DateTimePicker1->Time))); /* Get the second from the selected date */ edSecond->Text = IntToStr(SecondOf(TimeOf(DateTimePicker1->Time))); /* Get the millisecond from the selected date */ edMilliSecond->Text = IntToStr(MilliSecondOf(TimeOf(DateTimePicker1->Time))); } //--------------------------------------------------------------------------- void __fastcall TMainForm::btGetFirstDateClick(TObject *Sender) { /* Write the selected date in the first edit-box */ edFirstDate->Text = DateToStr(DateOf(DateTimePicker1->DateTime)); } //--------------------------------------------------------------------------- void __fastcall TMainForm::btGetSecondDateClick(TObject *Sender) { /* Write the selected date in the second edit-box */ edSecondDate->Text = DateToStr(DateOf(DateTimePicker1->DateTime)); } //--------------------------------------------------------------------------- void __fastcall TMainForm::btCompareDatesClick(TObject *Sender) { Integer CompResult; mmInfo->Lines->Clear(); /* Compares the two dates */ CompResult = CompareDate(StrToDate(edFirstDate->Text), StrToDate(edSecondDate->Text)); /* Write the date in the memo */ mmInfo->Lines->Add("First date: " + edFirstDate->Text); mmInfo->Lines->Add("Second date: " + edSecondDate->Text); /* Write the result of the comparison */ if (CompResult == LessThanValue) mmInfo->Lines->Add("The first date is before the second date."); if (CompResult == EqualsValue) mmInfo->Lines->Add("The first date is the same as the second date."); if (CompResult == GreaterThanValue) mmInfo->Lines->Add("The first date is after the second date."); }
Uses
- System.DateUtils.CompareDate ( fr | de | ja )
- System.DateUtils.DateOf ( fr | de | ja )
- System.DateUtils.DayOf ( fr | de | ja )
- System.DateUtils.HourOf ( fr | de | ja )
- System.DateUtils.MilliSecondOf ( fr | de | ja )
- System.DateUtils.MinuteOf ( fr | de | ja )
- System.DateUtils.MonthOf ( fr | de | ja )
- System.DateUtils.SecondOf ( fr | de | ja )
- System.DateUtils.TimeOf ( fr | de | ja )
- System.DateUtils.Today ( fr | de | ja )
- System.DateUtils.YearOf ( fr | de | ja )
- System.DateUtils.Yesterday ( fr | de | ja )
- Vcl.ComCtrls.TDateTimePicker ( fr | de | ja )
- Vcl.ComCtrls.TCommonCalendar.Date ( fr | de | ja )
- Vcl.ComCtrls.TDateTimePicker.DateTime ( fr | de | ja )
- Vcl.ComCtrls.TDateTimePicker.Format ( fr | de | ja )
- Vcl.ComCtrls.TDateTimePicker.Time ( fr | de | ja )