Board index » delphi » Calculating Difference Between Dates?
Dan
![]() Delphi Developer |
Mon, 28 Jul 2003 05:04:33 GMT
|
Dan
![]() Delphi Developer |
Mon, 28 Jul 2003 05:04:33 GMT
Calculating Difference Between Dates?
DateTime values are coming in from SQL Server.
Is there a Delphi function that will return to time difference of two Example: |
Christopher Latt
![]() Delphi Developer |
Mon, 28 Jul 2003 05:24:56 GMT
Re:Calculating Difference Between Dates?Whats wrong with: datediff := onedate - otherdate; where they are all TDateTime variables? If you want to format it, use the FormatDateTime function. Christopher Latta http://www.ozemail.com.au/~clatta QuoteDan wrote in message <3a81b867$1_2@dnews>... |
Kevin Frever
![]() Delphi Developer |
Mon, 28 Jul 2003 05:32:57 GMT
Re:Calculating Difference Between Dates?Dan, There is the MSSQL function DateDiff Select DateDiff(hh,'01/01/2001 15:00','01/01/2001 17:00') Check out the Books Online for other date/time functions. Good luck, QuoteDan wrote in message <3a81b867$1_2@dnews>... |
Dan
![]() Delphi Developer |
Mon, 28 Jul 2003 06:20:04 GMT
Re:Calculating Difference Between Dates?Quote> Whats wrong with: 2:00AM' The answer I'm looking for would be 26 hours. . . Dan |
Dan
![]() Delphi Developer |
Mon, 28 Jul 2003 06:44:43 GMT
Re:Calculating Difference Between Dates?Since I'm sure someone out there has done this I'll ask a different way. . . . I'm writing a timeclock program. . .SQL stores Delphi's NOW when employee Now it is time to figure how many hours that employee worked using a I know I can grunt work it out - but I'm trying to work smarter if you know Regards, |
Team
![]() Delphi Developer |
Mon, 28 Jul 2003 08:19:37 GMT
Re:Calculating Difference Between Dates?QuoteDan wrote in message <3a81cfe5$1_2@dnews>... DecodeDate(EarlierDateTime, yy, mnth, dd); DecodeTime(EarlierDateTime, hh, mm, ss, ms); -- |
Alain Quesne
![]() Delphi Developer |
Mon, 28 Jul 2003 10:48:14 GMT
Re:Calculating Difference Between Dates?Try var You would need to decide what to do with the minutes, of course. A TDateTime variable is just a float that represents days + the fraction of For instance, at the time of wrinting this, "Now" is equal to -- Alain Quesnel Quote"Dan" <d...@emscoelectric.com> wrote in message news:3a81ca1f_2@dnews... |
Bryan Valenci
![]() Delphi Developer |
Tue, 29 Jul 2003 04:21:04 GMT
Re:Calculating Difference Between Dates?
Hours:double; begin //the times are stored as floats with each whole day as an integer Hours:=(EndTime-StartTime)*24; end; QuoteDan wrote: MOST OF THE TIME I SEND MESSAGES TO THE PERSON OR ORGANIZATION I Bryan Valencia |
Bryan Valenci
![]() Delphi Developer |
Tue, 29 Jul 2003 04:24:27 GMT
Re:Calculating Difference Between Dates?QuoteBryan Valencia wrote: now. |
Alain Quesne
![]() Delphi Developer |
Tue, 29 Jul 2003 09:31:27 GMT
Re:Calculating Difference Between Dates?BTW, if you use FormatDateTime with a value that represents 25 hours (or more), it will return '01', since the 24 hours represent one day. -- Alain Quesnel Quote"Bryan Valencia" <br...@209software.com> wrote in message Hours:double; Starttime, EndTime:tDateTime; begin //load the datatimes from your database (or NOW). //the times are stored as floats with each whole day as an integer //and the time of day as the decimal. //let's say he came in a 8AM and left at 5PM. //StartTime would be the day integer number + 8/24ths of a day (.33333). //EndTime would be the Day Number + 17/24ths // (5pm is 17 o'clock) of a day .7083333). // or the answer would be .375 (of a day) or 9/24ths. // to get hours, all you do is multiply by 24 which gives 9. // You CAN use formatdatetime, but the date information //has been subtracted out. // just use formatdatetime('hh:nn',Hours); // The beauty of this is that it works for grave shift too, // where the employee came to work at 11PM Monday and left at // 8AM Tuesday. For instance starting at 1 23/24 and ending at // 2 8/24 (or 1.958333 and 2.333333) gives .375 of a day or // 8 hours. Hours:=(EndTime-StartTime)*24; QuoteDan wrote: . I'm writing a timeclock program. . .SQL stores Delphi's NOW when employee clocks in/out. . . Now it is time to figure how many hours that employee worked using a StartTime and EndTime (both TDateTime vars). . . I know I can grunt work it out - but I'm trying to work smarter if you know what I mean. . . Regards, Dan -- MOST OF THE TIME I SEND MESSAGES TO THE PERSON OR ORGANIZATION I INTENDED TO SEND THEM TO. WHEN THAT HAPPENS, FEEL FREE TO GO AHEAD AND READ THEM. IF THIS IS NOT THE PERSON I INTENDED TO SEND TO, PLEASE DISCARD THIS MESSAGE. IF YOU AREN'T SURE WHETHER THIS MESSAGE IS FOR YOU, THEN READ IT ONLY WITH YOUR LEFT EYE. Bryan Valencia bry...@eloan.com E-LOAN Inc. - A Better way to get a loan. |
1. Calculating Differences between dates and times
2. Trying to calculate difference between two DATES
3. Calculating the difference of twe date
4. How do calculate the difference between two dates ?
5. Local SQL, calculated fields, difference between 2 dates
6. Local SQL, calculated fields, difference between 2 dates
7. Calculating time differences in SQL
8. Calculate difference between a row and its row immediatly following it