Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert Elapsed Seconds to Date/Time?

1,783 views
Skip to first unread message

John Topley

unread,
Jan 1, 1999, 3:00:00 AM1/1/99
to
How can I resolve the number of seconds that have elapsed since an arbitrary
starting date and time into a date and time value?

Many thanks,

--
John

(JTSoftware - http://ds.dial.pipex.com/john.topley)

mike

unread,
Jan 1, 1999, 3:00:00 AM1/1/99
to
>How can I resolve the number of seconds that have elapsed since an arbitrary
>starting date and time into a date and time value?

Assuming you're using tDateTime variables, you really don't need to
keep track of the number of seconds:

var
Start, Elapsed : tDatetime;
begin
Start := Now;
{ do something time consuming here }
Elapsed := Now - Start;
end;

However, if you really do need to use seconds, there is a SecsPerDay
constant that you can use:

Elapsed := Seconds / SecsPerDay;

-Mike

Moz (Chris Moseley)

unread,
Jan 2, 1999, 3:00:00 AM1/2/99
to

John Topley wrote in message <76j2ua$29...@forums.borland.com>...

>How can I resolve the number of seconds that have elapsed since an arbitrary
>starting date and time into a date and time value?


TDateTime is a number just like that, so it's fairly easy. SecsPerDay is a Delphi
constant used as below, MyStartDate is a string with the origin of your time
counter in it and SecondsSince is the number of seconds you have.

MyDateTime := StrToDateTime(MyStartDate) + (SecondsSince / SecsPerDay)

The TDateTime help is quite useful on this subject:

"type TDateTime = type Double;

" Delphi stores date and time values in the TDateTime type. 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 the time of day."

"Example: TDateTime(0) = 12/30/1899 12:00 am"

HTH
Moz


M.Wasbauer

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to
Hello Moz,

My name is maurice Wasbauer and I read your follow up to a DateTime
question. It seems that you have quite some knowledge about this.
I also have a question related to this subject and maybe you can help
me out.

Is there a way to add or subtract a certain period of hours and/or
minutes of the systemtime and convert the output to a string so I can
display it as a label caption ?

The purpose is to calculate the GMT (Greenwich Mean Time) from the
local (system) time.. Or even more beautiful: make a calculation
between the systemtime and the timezone to automatically calculate the
GMT ???

Hope to hear from you..

Greetings,

Maurice (M.Wasbauer <M.Was...@mcse-nl.demon.nl>

Moz (Chris Moseley)

unread,
Jan 13, 1999, 3:00:00 AM1/13/99
to

M.Wasbauer wrote in message <369b276b...@news.demon.nl>...

>Is there a way to add or subtract a certain period of hours and/or
>minutes of the systemtime and convert the output to a string so I can
>display it as a label caption ?

DateTimeToStr() or FormatDateTime will do the string conversion, and
the same technique I suggested before will work for you, although
you will need to convert your days and hours into seconds.

>The purpose is to calculate the GMT (Greenwich Mean Time) from the
>local (system) time..

I believe there are API calls that will tell you this directly. Not
sure what they are, but Delphi Help will probably have them, and if
not try MSDN or the MS web site.

Moz


0 new messages