# Board index » delphi » Q: Calculate seconds passed since midnight???

## Q: Calculate seconds passed since midnight???

Can anyone help me on a routine which calculates the number of seconds
passed since midnight?!

btw. i'm working in Delphi-4.

Thanks a million.

T.

## Re:Q: Calculate seconds passed since midnight???

Look into your helpfile and search for the DecodeTime function. It cuts the
time up into separate vars which you can easily multply to calculate the
seconds past 00:00:00

Jaap

Theo van der Winden wrote in message <36dd846c.409...@news.tip.nl>...

##### Quote
>Can anyone help me on a routine which calculates the number of seconds
>passed since midnight?!

>btw. i'm working in Delphi-4.

>Thanks a million.

>T.

## Re:Q: Calculate seconds passed since midnight???

Theo van der Winden wrote:

##### Quote

> Can anyone help me on a routine which calculates the number of seconds
> passed since midnight?!

var
E:extended;
begin
E:=(Now-Date)*86400;

Greetings to your professor, if this was one of your home works:)

Markku Nevalainen

## Re:Q: Calculate seconds passed since midnight???

Theo.van.der.Win...@tip.nl (Theo van der Winden) wrote:

##### Quote
>Can anyone help me on a routine which calculates the number of seconds
>passed since midnight?!

iSecondsSinceMidnight := Trunc( Time * 24.0 * 60.0 * 60.0 );
--
- Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

## Re:Q: Calculate seconds passed since midnight???

I think this would work (although I haven't compiled it):

function SecsSince12 : integer;
var
wHour, wMin, wSec, wMSec : Word;
begin
DecodeTime(Now, wHour, wMin, wSec, wMSec);
SecsSince12 := wHour * 3600 + wMin * 60 + wSec;
end;

Christopher Latta

Theo van der Winden wrote in message <36dd846c.409...@news.tip.nl>...

##### Quote
>Can anyone help me on a routine which calculates the number of seconds
>passed since midnight?!

## Re:Q: Calculate seconds passed since midnight???

On Wed, 03 Mar 1999 18:50:23 GMT, Theo.van.der.Win...@tip.nl (Theo van

##### Quote
der Winden) wrote:
>Can anyone help me on a routine which calculates the number of seconds
>passed since midnight?!

Everyone is posting a solution that are, more or less, identical. Here's
a solution that I personally find clear and readable:

var
SecondsSinceMidnight: 0..SecsPerDay;
begin
SecondsSinceMidnight := Round(Time * SecsPerDay);

--
Ray Lischner  (http://www.bardware.com)
co-author (with John Doyle) of Shakespeare for Dummies

## Re:Q: Calculate seconds passed since midnight???

No no no! You all guys are not right. You don't need to calculate anything.
Simply:

Var
A : TTimeStamp;
SecsPastMid : Integer;
Begin
A:=DateTimeToTimeStamp(Time);
SecsPastMid:=A.Time div 1000;
End;

And thats all!

##### Quote
Ray Lischner wrote:

> On Wed, 03 Mar 1999 18:50:23 GMT, Theo.van.der.Win...@tip.nl (Theo van
> der Winden) wrote:

> >Can anyone help me on a routine which calculates the number of seconds
> >passed since midnight?!

> Everyone is posting a solution that are, more or less, identical. Here's
> a solution that I personally find clear and readable:

> var
>   SecondsSinceMidnight: 0..SecsPerDay;
> begin
>   SecondsSinceMidnight := Round(Time * SecsPerDay);

> --
> Ray Lischner  (http://www.bardware.com)
> co-author (with John Doyle) of Shakespeare for Dummies

--
|  Algirdas 'Ze{*word*104}' Kepezinskas
|  E-Mail: cy...@vil.ktu.lt
|  ICQ 14187537
|  URL: http://www.botepidemic.com/fmods
+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*++*+*+*+*
|  If time is killing you
|                   kill some for time..

## Re:Q: Calculate seconds passed since midnight???

In article <36DE913D.8B5A4...@vil.ktu.lt>, Algirdas Kepezinskas

##### Quote
<cy...@vil.ktu.lt> writes:
>No no no! You all guys are not right. You don't need to calculate anything.
>Simply:

>Var
>  A : TTimeStamp;
>  SecsPastMid : Integer;
>Begin
> A:=DateTimeToTimeStamp(Time);
> SecsPastMid:=A.Time div 1000;
>End;

So what's this A.Time div 1000 - isn't div a calculation <g>

I know I'd much rather see Ray's code (and understand it) than puzzle out what
yours is doing - I'd wonder what TimeStamp (used with files) was to do with
seconds past midnight.

Code clarity is (nearly) all.

Alan Lloyd
alangll...@aol.com