RE: Time
"Andre du Plessis" <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <001701c3448c$18d10e90$1c0044c0@ANDRE> |
Hey I digged up this old function I wrote ages ago when I wanted to do
something similar, unformat a date that was formatted using the same
string passed to FormatDateTime, the nice thing about it is you can use
format strings.
it should work but have not checked/tested it
lately:
function UnFormatDateTime( vFmtStr, vDate: string): TDateTime;
var
lYear ,
lMonth,
lDay ,
lHour ,
lMin ,
lSec ,
lHun : string;
I : Integer;
begin
I := 1;
if Length (vDate) <> Length (vFmtStr) then begin
Result := 0;
Exit;
end;
while I <= Length(vFmtStr) do begin
if UpCase(vFmtStr[I]) = 'Y' then begin
lYear := lYear + vdate[i];
end
else if UpCase(vFmtStr[i]) = 'M' then begin
lMonth := lMonth + vDate[i];
end
else if UpCase(vFmtStr[i]) = 'D' then begin
lDay := lDay + vDate[i];
end
else if UpCase(vFmtStr[i]) = 'H' then begin
lHour := lHour + vDate[i];
end
else if UpCase(vFmtStr[i]) = 'N' then begin
lMin := lMin + vDate[i];
end
else if UpCase(vFmtStr[i]) = 'S' then begin
lSec := lSec + vDate[i];
end
else if UpCase(vFmtStr[i]) = 'Z' then begin
lHun := lHun + vDate[i];
end;
Inc (I);
end;
if Length (lYear) = 2 then lYear := '19' + lYear;
if lYear = '' then lYear := '0';
if lMonth= '' then lMonth := '0';
if lDay = '' then lDay := '0';
if lHour = '' then lHour := '0';
if lMin = '' then lMin := '0';
if lSec = '' then lSec := '0';
if lHun = '' then lHun := '0';
Result := EncodeDate ( StrToInt (lYear), StrToInt (lMonth), StrToInt
(lDay))
+ EncodeTime ( StrToInt (lHour), StrToInt (lMin), StrToInt
(lSec), StrToInt (lHun));
end;
-----Original Message-----
From: Angelos Markos [mailto:[email protected]]
Sent: Monday, July 07, 2003 2:59 PM
To: [email protected]
Subject: Re: [Delphi] Time
Try the following function:
function GetTimeInSec:Integer;
var h,m,s,ms:Word;
begin
DecodeTime(Time,h,m,s,ms);
Result:=h*360+m*60+s;
end;
----------------------------------------------
Angelos I. Markos
Phd Student
Department of Applied Informatics
University of Macedonia, Thessaloniki
Greece
----- Original Message -----
From: Eduardo Meyer
To: [email protected]
Sent: Monday, July 07, 2003 3:51 PM
Subject: Re: [Delphi] Time
Hi Mike,
I'm sorry, I think I haven't expressed that in the right way.
Imagine that I have a Time value as (12:54:05).
I would like to know know many seconds does it has.
12:43:05 = 45785 seconds
That's it.
Is there a function that do it?
Thanks a lot!
Eduardo
----- Original Message -----
From: Shkolnik M.
To: [email protected]
Sent: Monday, July 07, 2003 9:40 AM
Subject: RE: [Delphi] Time
>Is there a function which convert a time data as ( 1:00:03 ) in
seconds?
You need the FormatDateTime function:
str := FormatDateTime('hh:nn:ss', yourTimeVar);
With best regards, Mike Shkolnik
EMail: [email protected]
http://www.scalabium.com
Yahoo! Groups Sponsor
ADVERTISEMENT
Delphi Tips & Tutorials...
http://www.delphicollection.com
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
[Non-text portions of this message have been removed]
Yahoo! Groups Sponsor
ADVERTISEMENT
Delphi Tips & Tutorials...
http://www.delphicollection.com
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
[Non-text portions of this message have been removed]
Delphi Tips & Tutorials...
http://www.delphicollection.com
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Inkjet cartridges up to 80% off. HP, Epson, Lexmark--we have your brand.
Free shipping on every order to the U.S. and Canada! Excellent service.
http://www.c1tracking.com/l.asp?cid=5510
http://us.click.yahoo.com/QWB0QC/.eUGAA/ySSFAA/i7folB/TM
---------------------------------------------------------------------~->
Delphi Tips & Tutorials...
http://www.delphicollection.com
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/