BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Time calculation

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
Geir Baardsen
Guest





PostPosted: Sun Jan 09, 2005 8:21 am    Post subject: Time calculation Reply with quote



Hi!
My app is a personal scheduler. I use a stringgrid with 10 columns:

MonIN MonOUT TueIN TueOUT WedIN WedOUT ThuIN ThuOUT FriIN FriOUT

when I click a cell, the time will be set in the format of:

FormatDateTime('HH:MM',time);

So now I want to calculate the total in time between MonIN and FriOUT.

I should surely convert it or cast it to a double, not so?

var
Monsum:double;
begin
for i := 0 to StrToFloat(grSched.Cells[1,Monsum]);

Anybody that have an example of how to work with time?

Me.Name
Back to top
Tom de Neef
Guest





PostPosted: Sun Jan 09, 2005 10:08 am    Post subject: Re: Time calculation Reply with quote



"Geir Baardsen" <geir_baardsen (AT) hotmail (DOT) com> schreef in bericht
news:35f9d8b7.0501090021.7e56782c (AT) posting (DOT) google.com...
Quote:
Hi!
My app is a personal scheduler. I use a stringgrid with 10 columns:

MonIN MonOUT TueIN TueOUT WedIN WedOUT ThuIN ThuOUT FriIN FriOUT

when I click a cell, the time will be set in the format of:

FormatDateTime('HH:MM',time);

So now I want to calculate the total in time between MonIN and FriOUT.


Check help: TdateTime
"The integral part of a TDateTime value is the number of days that have
passed since 12/30/1899. The fractional part of a TDateTime value is
fraction of a 24 hour day that has elapsed."

So,
difference:=FriOUT-MonIN;
is the elapsed time between these two.
trunc(difference) is then the number of days
trunc(difference*24) the number of full hours elapsed, etc.

Tom



Back to top
Jamie
Guest





PostPosted: Sun Jan 09, 2005 7:11 pm    Post subject: Re: Time calculation Reply with quote



Geir Baardsen wrote:
Quote:
Hi!
My app is a personal scheduler. I use a stringgrid with 10 columns:

MonIN MonOUT TueIN TueOUT WedIN WedOUT ThuIN ThuOUT FriIN FriOUT

when I click a cell, the time will be set in the format of:

FormatDateTime('HH:MM',time);

So now I want to calculate the total in time between MonIN and FriOUT.

I should surely convert it or cast it to a double, not so?

var
Monsum:double;
begin
for i := 0 to StrToFloat(grSched.Cells[1,Monsum]);

Anybody that have an example of how to work with time?

Me.Name
the TDateTime type is a double, the fraction is the

fraction of the day.
in other words, 0.5 would be 12:00 and 0.0 would be
be 24:00 (midnight) etc..
i guess one could take a DataTime's fraction and turn that into
an integer by taking the scale you want for the day and * the Fraction.
for example, the N = SecondsOfTheDay = (DateTime-Trunc(DateTime))*86400;
ect.
from there i think you can work that out.





Back to top
Dr John Stockton
Guest





PostPosted: Sun Jan 09, 2005 8:17 pm    Post subject: Re: Time calculation Reply with quote

JRS: In article <35f9d8b7.0501090021.7e56782c (AT) posting (DOT) google.com>,
dated Sun, 9 Jan 2005 00:21:25, seen in news:comp.lang.pascal.delphi.mis
c, Geir Baardsen <geir_baardsen (AT) hotmail (DOT) com> posted :

Quote:
MonIN MonOUT TueIN TueOUT WedIN WedOUT ThuIN ThuOUT FriIN FriOUT

when I click a cell, the time will be set in the format of:

FormatDateTime('HH:MM',time);

So now I want to calculate the total in time between MonIN and FriOUT.

There is no need to bother with TDateTime. You have days 1..5 of the
ISO 8061:2004 week, you have 24 hours per day and 60 minutes per hour.

Just take each HH:MM string, copy HH & MM, use Val or maybe StrToInt,
then Mins := HH*60+MM, etc.

With TDateTime, since the data is stored as a float binary of days, and
the number of H M S in a day is not a power of 2, there must be some
risk of rounding error; with integer arithmetic, all is exact.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.