whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

21 Visitors Online


 
...convert TDateTime to Unix Timestamp?
Autor: Thomas Greiner
Homepage: http://www.economx.com
[ Print tip ]  

Tip Rating (33):  
     


{
  Sometimes you want to communicate with mySQL or other databases using
  the unix timestamp. To solve this difference you may want to convert your
  TDateTime to the unix timestamp format and vice versa.

  Um den in einigen Datenbanken verwendeten Unix Timestamp für die Kommunikation
  mit Delphi nutzbar zu machen, kann man mit dieser Unit das TDateTime Format
  in den Unix Timestamp und umgekehrt umwandeln.
}

unit unix_utils;

interface

implementation

const
  
// Sets UnixStartDate to TDateTime of 01/01/1970
  
UnixStartDate: TDateTime = 25569.0;

function DateTimeToUnix(ConvDate: TDateTime): Longint;
begin
  
//example: DateTimeToUnix(now);
  
Result := Round((ConvDate - UnixStartDate) * 86400);
end;

function UnixToDateTime(USec: Longint): TDateTime;
begin
  
//Example: UnixToDateTime(1003187418);
  
Result := (Usec / 86400) + UnixStartDate;
end;

end.


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners