كيفية حساب عدد الساعات بين تاريخين محددين
#4
كود :
procedure TMainForm.btCompareDatesClick(Sender: TObject); var Result: Integer; begin mmInfo.Lines.Clear; { Compares the two dates } Result := 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 Result = LessThanValue then mmInfo.Lines.Add('The first date is before the second date.'); if Result = EqualsValue then mmInfo.Lines.Add('The first date is the same as the second date.'); if Result = GreaterThanValue then mmInfo.Lines.Add('The first date is after the second date.'); end; procedure TMainForm.btGetFirstDateClick(Sender: TObject); begin { Write the selected date in the first edit-box } edFirstDate.Text := DateToStr(DateOf(DateTimePicker1.DateTime)); end; procedure TMainForm.btGetInfoClick(Sender: TObject); begin { 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))); end; procedure TMainForm.btGetSecondDateClick(Sender: TObject); begin { Write the selected date in the second edit-box } edSecondDate.Text := DateToStr(DateOf(DateTimePicker1.DateTime)); end; procedure TMainForm.FormCreate(Sender: TObject); begin 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); end;
الرد


الردود في هذا الموضوع
كيفية حساب عدد الساعات بين تاريخين محددين - بواسطة cargem - 31-07-2011, 02:03 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم