TIP: Click on subject to list as thread! ANSI
echo: delphi
to: JOAQUIM HOMRIGHAUSEN
from: LEE LEFLER
date: 1997-11-19 23:42:00
subject: D1: EncodeTime() / EncodeDate()

Hello Joaquim!
Replying to a message of Joaquim Homrighausen to All:
 JH>   Do the above two function retain other values in the TDateTime
 JH> return variable across calls? I mean, how would I go about encoding a
 JH> given date *and* time into a variable of TDateTime type?
        I don't know if this is what you are asking, but...  TDateTime is a 
Double.  It stores the date information in the integer portion.  According 
the my online help, it is the number of days since 12/30/1899.  The 
fractional part is the fraction of the 24 hour day that has elapsed.  (almost 
a direct quote)
        Using EncodeTime and EncodeDate you can save any time stamp in a 
Double (TDateTime).   You should be able to store the date in a variable with 
encode date followed by the time with encode time without losing the prior 
result.  But I think maybe you might be wanting something like StrToDateTime 
instead.
      Var
        TimeStamp        : TDateTime;
      Begin
        TimeStamp := StrToDateTime('11/19/97 23:48:18');
      End;
        Of course you can also do a lot more with it:  Timestamp1 - 
Timestamp2 can give you the difference in days or time, or both.  For some of 
the things I suspect you will be using.....
        Var
          ReferenceDate  : TDateTime;
          FirstOfYear  : TDateTime;
          wYear        : Word;
          wMonth        : Word;
          wDay        : Word; 
          wHour       : Word; 
          wMin        : Word; 
          wSec        : Word; 
          wMSec       : Word; 
          lUnixTimeStamp : LongInt;
        Begin
           DecodeDate(Now, wYear, wMonth, wDay);
           FirstOfYear := StrToDate('01/01/' + IntToStr(wYear));
           wDay := Trunc(Now - FirstOfYear)
           // It is now day wDay.....
           //
           //And the ever famous, unix timestamp.
           //
           ReferenceDate := StrToDateTime('01/01/70 00:00:00');
           wDay := Trunc(Now - ReferenceDate);
           DecodeTime(Now, wHour, wMin, wSec, wMSec);       
           lUnixTimeStamp := (wDay * 86400) + (wHour * 3600) + (wMin * 60) + 
wSec;
           //  Hmm, (wDay * 86400) + Trunc((Now - Trunc(Now)) * 86400) works 
as well.
        End; 
        This is of course, untested.  And I guess I got a little carried 
away. 
      
Bye, Lee!
---------------
* Origin: Infinity (1:280/5)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.