![]() |
|
كيفية حساب عدد الساعات بين تاريخين محددين - نسخة قابلة للطباعة +- delphi4arab منتديات دلفي للعرب (https://delphi4arab.net/forum) +-- قسم : منتديات دلفي للعرب التعليمية (https://delphi4arab.net/forum/forumdisplay.php?fid=3) +--- قسم : سؤال و جواب حول دلفي (https://delphi4arab.net/forum/forumdisplay.php?fid=15) +--- الموضوع : كيفية حساب عدد الساعات بين تاريخين محددين (/showthread.php?tid=3329) |
كيفية حساب عدد الساعات بين تاريخين محددين - SOFIANE09 - 30-07-2011 السلام عليكم لدي برنامج تطبيقة من خلاله حساب عدد الساعات بين تارخين بمعنى اضع تاريخ اليوم مع ساعة البدء و اضع تاريخ الغد مع ساعة النهاية وعندما اقوا له عد يقوم بعد عدد الساعات بين التريخين البرنامج مرفق مستعجل اخواني اجركم على الله كيفية حساب عدد الساعات بين تاريخين محددين - cargem - 31-07-2011 كود : var
fromdate, toDate : TDateTime;
begin
// Set up our date variables
fromDate := EncodeDateTime(2000, 02, 26, 10, 0, 0, 0);
toDate := EncodeDateTime(2000, 02, 29, 9, 0, 0, 0);
// Display these dates and the days between them
ShowMessage('From date = '+DateTimeToStr(fromDate));
ShowMessage('To date = '+DateTimeToStr(toDate));
ShowMessage('Whole days difference = '+
IntToStr(DaysBetween(toDate, fromDate))+' days');
end;إقتباس :Show full unit code or use: DateUtils, IdGlobalProtocols كود : procedure TForm1.Button1Click(Sender: TObject);
var
day, hour: Integer;
fromdate, toDate: TDateTime;
begin
fromdate := Date1.Date;
toDate := Date2.Date;
day := DaysBetween(toDate, fromdate);
fromdate := Date1.Time;
toDate := Date2.Time;
hour := DaysBetween(toDate, fromdate) ;
hour :=hour + day*24 ;
heure1.Text := IntToStr(hour) ;
// day := CompareDateTime(Date2.DateTime, Date1.DateTime ) ;
// hour := CompareDateTime(Date2.Time, Date1.Time ) ; ;
// hour :=hour + day*24 ;
end;كيفية حساب عدد الساعات بين تاريخين محددين - cargem - 31-07-2011 كود : 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 كود : 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 إقتباس :Call CompareDate to compare the two TDateTime values specified by A and B. CompareDate returns: كود : 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;كيفية حساب عدد الساعات بين تاريخين محددين - SOFIANE09 - 02-08-2011 ممكن ات تطبق الكود سورس على التطبيق الذي وصعته اخي الكريم شكرا لك على المجهود كيفية حساب عدد الساعات بين تاريخين محددين - cargem - 03-08-2011 كود : procedure TForm1.Button1Click(Sender: TObject);
var
fromdate, toDate : TDateTime;
begin
// Set up our date variables
fromDate := EncodeDateTime(1899, 12, 30, 5, 09, 00, 0);// 12/30/1899 5:09:00 PM
//
toDate := EncodeDateTime(2011, 08, 03, 6, 29, 05, 0); // 8/3/2011 6:29:05 PM
//
// Display these dates and the days between them
ShowMessage('From date = '+DateTimeToStr(fromDate));
ShowMessage('To date = '+DateTimeToStr(toDate));
ShowMessage('Whole days difference = '+
IntToStr(DaysBetween(toDate, fromDate))+' days');
ShowMessage('Whole hours difference = '+
IntToStr(HoursBetween(toDate, fromDate))+' hours');
end;كيفية حساب عدد الساعات بين تاريخين محددين - SOFIANE09 - 03-08-2011 السلام اخي هنا المشكل فلم يتعرف على DaysBetween كيفية حساب عدد الساعات بين تاريخين محددين - SOFIANE09 - 03-08-2011 لقد عرفت مشاكل كثيرة في الكود سورس اخي الكريم ممكن ان ترفق الكود سوري في البرنامج الذي وضعته انا وكون شاكرا لك رمضان كريم صديقي كيفية حساب عدد الساعات بين تاريخين محددين - cargem - 03-08-2011 عملت لك اسورس وصورة ولكن انقعت الكهرباء حضك نحس!! ولكن ساعمل لك مرة ثاني |