Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking client machine Date against server Date

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
How can I check whether or not I have a match between my client machine (system) date and the server (system) date ?

We have seen instances when a client machine has had a different (future) date set [due to testing on a local machine for some reason] and when running Delphi code that makes use of the 'Now'/'Date' calls then inputs misleading date stamps in data on the server.

We're looking for ways to determine whether or not all our dates on machines are in line.
Can this be done ?

Thanks in advance

Steve
 
Hey Steve. Here's the example that might help you:
Code:
....
type
   TIME_OF_DAY_INFO  = record
     tod_elapsedt     : DWord;
     tod_msecs        : DWord;
     tod_hours        : DWord;
     tod_mins         : DWord;
     tod_secs         : DWord;
     tod_hunds        : DWord;
     tod_timezone     : LongInt;
     tod_tinterval    : DWord;
     tod_day          : DWord;
     tod_month        : DWord;
     tod_year         : DWord;
     tod_weekday      : DWord;
   end;
   PTIME_OF_DAY_INFO = ^TIME_OF_DAY_INFO;
  
   LPBYTE           = ^Byte;
   NET_API_STATUS   = DWord;
...
{EXTERNAL DECLARATIONS}
  function NetRemoteTOD(HostName: PWideChar; 
                        Buffer: LPBYTE): NET_API_STATUS;
   stdcall; external 'netapi32.dll' name 'NetRemoteTOD';
  {$EXTERNALSYM NetRemoteTOD}
...
implementation

function GetRemoteTOD(Host: WideString; TODInfo: LPBYTE): Boolean;
begin
  Result := (NetRemoteTOD(pWideChar(Host), TODInfo) = 0);
end;

function GetRemoteDateTime(Host: WideString): TDateTime;
var
  TOD   : PTIME_OF_DAY_INFO;
begin
  if NetRemoteTOD(pWideChar(Host), @TOD) = 0 then
   Result := EncodeDate(TOD^.tod_year, TOD^.tod_month, TOD^.tod_day) +
             EncodeTime(TOD^.tod_hours, TOD^.tod_mins, TOD^.tod_secs, TOD^.tod_hunds * 10) -
             TOD^.tod_timezone / 60 / 24
  else
   Result := 0;
end;
All you need to do is to make a call to GetRemoteDateTime, specifing a host name you want to get DateTime info from.
HTH.

--- markus

P.S. I don't remember if you have to call NetAPIBufferFree after calling to NetRemoteTOD, but the example works with me and there always a manual (and the forum of course) where you can ask for details.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top