DTStartEnd (Delphi)
Description
This example demonstrates the use of some routines in the DateUtils unit.
Code
var
DateTime: TDateTime;
procedure TMainForm.btProcessClick(Sender: TObject);
var
number: Integer;
begin
Memo1.Lines.Clear;
number := StrToInt(edInc.Text);
{ Increase a specific portion of the TDateTime variable }
if RadioGroup1.ItemIndex = 0 then
DateTime := IncMilliSecond(DateTime,number);
if RadioGroup1.ItemIndex = 1 then
DateTime := IncSecond(DateTime,number);
if RadioGroup1.ItemIndex = 2 then
DateTime := IncMinute(DateTime,number);
if RadioGroup1.ItemIndex = 3 then
DateTime := IncHour(DateTime,number);
if RadioGroup1.ItemIndex = 4 then
DateTime := IncDay(DateTime,number);
if RadioGroup1.ItemIndex = 5 then
DateTime := IncMonth(DateTime,number);
if RadioGroup1.ItemIndex = 6 then
DateTime := IncYear(DateTime,number);
Edit1.Text := DateTimeToStr(DateTime);
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
DateTime := Date + Time;
{ Verify if the time portion of the TDateTime variable occurs after noon }
if IsPM(DateTime) then
ShowMessage('It is after-noon')
else
ShowMessage('It is morning');
{ Write the start and the end of current date }
Edit1.Text := DateTimeToStr(DateTime);
Memo1.Lines.Add('Start of the year: ' +
DateTimeToStr(StartOfTheYear(DateTime)));
Memo1.Lines.Add('Start of the month: ' +
DateTimeToStr(StartOfTheMonth(DateTime)));
Memo1.Lines.Add('Start of the week: ' +
DateTimeToStr(StartOfTheWeek(DateTime)));
Memo1.Lines.Add('Start of the day: ' +
DateTimeToStr(StartOfTheDay(DateTime)));
Memo1.Lines.Add('Start of a year: ' +
DateTimeToStr(StartOfAYear(YearOf(DateTime))));
Memo1.Lines.Add('Start of a month: ' +
DateTimeToStr(StartOfAMonth(YearOf(DateTime),MonthOf(DateTime))));
Memo1.Lines.Add('Start of a week: ' +
DateTimeToStr(StartOfAWeek(YearOf(DateTime),WeekOf(DateTime))));
Memo1.Lines.Add('Start of a day: ' +
DateTimeToStr(StartOfADay(YearOf(DateTime),DayOf(DateTime))));
Memo1.Lines.Add('End of the year: ' +
DateTimeToStr(EndOfTheYear(DateTime)));
Memo1.Lines.Add('End of the month: ' +
DateTimeToStr(EndOfTheMonth(DateTime)));
Memo1.Lines.Add('End of the week: ' +
DateTimeToStr(EndOfTheWeek(DateTime)));
Memo1.Lines.Add('End of the day: ' +
DateTimeToStr(EndOfTheDay(DateTime)));
Memo1.Lines.Add('End of a year: ' +
DateTimeToStr(EndOfAYear(YearOf(DateTime))));
Memo1.Lines.Add('End of a month: ' +
DateTimeToStr(EndOfAMonth(YearOf(DateTime),MonthOf(DateTime))));
Memo1.Lines.Add('End of a week: ' +
DateTimeToStr(EndOfAWeek(YearOf(DateTime),WeekOf(DateTime))));
Memo1.Lines.Add('End of a day: ' +
DateTimeToStr(EndOfADay(YearOf(DateTime),DayOf(DateTime))));
end;
Uses
- System.DateUtils.EndOfADay ( fr | de | ja )
- System.DateUtils.EndOfAMonth ( fr | de | ja )
- System.DateUtils.EndOfAWeek ( fr | de | ja )
- System.DateUtils.EndOfAYear ( fr | de | ja )
- System.DateUtils.EndOfTheDay ( fr | de | ja )
- System.DateUtils.EndOfTheMonth ( fr | de | ja )
- System.DateUtils.EndOfTheWeek ( fr | de | ja )
- System.DateUtils.EndOfTheYear ( fr | de | ja )
- System.DateUtils.IncDay ( fr | de | ja )
- System.DateUtils.IncHour ( fr | de | ja )
- System.DateUtils.IncMilliSecond ( fr | de | ja )
- System.DateUtils.IncMinute ( fr | de | ja )
- System.DateUtils.IncSecond ( fr | de | ja )
- System.DateUtils.IncWeek ( fr | de | ja )
- System.DateUtils.IncYear ( fr | de | ja )
- System.DateUtils.IsPM ( fr | de | ja )
- System.DateUtils.StartOfADay ( fr | de | ja )
- System.DateUtils.StartOfAMonth ( fr | de | ja )
- System.DateUtils.StartOfAWeek ( fr | de | ja )
- System.DateUtils.StartOfAYear ( fr | de | ja )
- System.DateUtils.StartOfTheDay ( fr | de | ja )
- System.DateUtils.StartOfTheMonth ( fr | de | ja )
- System.DateUtils.StartOfTheWeek ( fr | de | ja )
- System.DateUtils.StartOfTheYear ( fr | de | ja )