If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Synchronize Server Time

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-04, 20:53
chneoh chneoh is offline
Registered User
 
Join Date: Mar 2004
Posts: 36
Unhappy Synchronize Server Time

Hi all the experts i have the problem in synchronize the server time with my client workstation! Because my application i wrote, all the date and time must get from the server time.

So can somebody show my how to get the server time and set the server time to local time.
Reply With Quote
  #2 (permalink)  
Old 03-24-04, 09:46
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
What OS / Database Engine does the server run? What OS / programming language does the client run?

-PatP
Reply With Quote
  #3 (permalink)  
Old 03-24-04, 20:16
chneoh chneoh is offline
Registered User
 
Join Date: Mar 2004
Posts: 36
Quote:
Originally posted by Pat Phelan
What OS / Database Engine does the server run? What OS / programming language does the client run?

-PatP
Server is Windows 2000 Server Family

and the client is Win9x to WinXp
Reply With Quote
  #4 (permalink)  
Old 03-24-04, 21:21
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
Ok, getting the server time is easy. Just use:
Code:
SELECT GetDate(), GetUTCDate()
and it will return a single row with one column with the current local server datetime, and another with the corresponding UTC datetime.

How you set that on the client varies a great deal, but you can use the Windows API call to SetSystemTime if nothing easier is available.

One option for you to consider that I would strongly recommend is to build all of the time sensitive logic into server side components (stored procedures, DCOM DLLs, or .NET assemblies). This allows you to make changes to the time sensitive code easily on the server instead of having to track down every blasted machine running a copy of your application.

-PatP
Reply With Quote
  #5 (permalink)  
Old 03-25-04, 01:17
chneoh chneoh is offline
Registered User
 
Join Date: Mar 2004
Posts: 36
Quote:
Originally posted by Pat Phelan
Ok, getting the server time is easy. Just use:
Code:
SELECT GetDate(), GetUTCDate()
and it will return a single row with one column with the current local server datetime, and another with the corresponding UTC datetime.

How you set that on the client varies a great deal, but you can use the Windows API call to SetSystemTime if nothing easier is available.

One option for you to consider that I would strongly recommend is to build all of the time sensitive logic into server side components (stored procedures, DCOM DLLs, or .NET assemblies). This allows you to make changes to the time sensitive code easily on the server instead of having to track down every blasted machine running a copy of your application.

-PatP
PatP the server i have i only the Domain Server and does not have any running database attach to it. So i cannot use your matter already.
Reply With Quote
  #6 (permalink)  
Old 03-25-04, 07:34
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
Ok, can you issue a command (possibly via a batch file)? If so, you could use:
Code:
 NET TIME [\\computer] [/SET] [/YES]
So, if your common timesource was named tick, you could use:
Code:
NET TIME \\tick /SET /YES
to make the current computer's time match the time on the tick server.

-PatP
Reply With Quote
  #7 (permalink)  
Old 03-25-04, 20:15
chneoh chneoh is offline
Registered User
 
Join Date: Mar 2004
Posts: 36
Quote:
Originally posted by Pat Phelan
Ok, can you issue a command (possibly via a batch file)? If so, you could use:
Code:
 NET TIME [\\computer] [/SET] [/YES]
So, if your common timesource was named tick, you could use:
Code:
NET TIME \\tick /SET /YES
to make the current computer's time match the time on the tick server.

-PatP
PatP i have tried this method before, but after i run the batch file, the dos prompt screen still maintain and cannot close automatically.
Reply With Quote
  #8 (permalink)  
Old 03-25-04, 21:13
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
What programming language are you using? For example in VB you could use the Shell() function to run the NET command.

-PatP
Reply With Quote
  #9 (permalink)  
Old 03-26-04, 01:35
chneoh chneoh is offline
Registered User
 
Join Date: Mar 2004
Posts: 36
Quote:
Originally posted by Pat Phelan
What programming language are you using? For example in VB you could use the Shell() function to run the NET command.

-PatP
Delphi 5
Reply With Quote
  #10 (permalink)  
Old 03-26-04, 08:53
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
I'd run the NET command using Delphi's ShellAPI to avoid the complications of batch files, etc.

-PatP
Reply With Quote
  #11 (permalink)  
Old 03-28-04, 20:15
chneoh chneoh is offline
Registered User
 
Join Date: Mar 2004
Posts: 36
Quote:
Originally posted by Pat Phelan
I'd run the NET command using Delphi's ShellAPI to avoid the complications of batch files, etc.

-PatP
I tried the WinExec on Delphi ShellAPI, but when run that command, the command prompt screen come out and cannot disappear
Reply With Quote
  #12 (permalink)  
Old 03-28-04, 21:45
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
It shows the window even when you supply the SW_HIDE value ?!?!

That smells like a bug to me! Are you using the current service packs for Delphi 5? I haven't kept track of the changes that were made that long ago, but I suspect that you might have found a problem that was fixed in a service pack.

-PatP
Reply With Quote
  #13 (permalink)  
Old 03-29-04, 04:47
chneoh chneoh is offline
Registered User
 
Join Date: Mar 2004
Posts: 36
Quote:
Originally posted by Pat Phelan
It shows the window even when you supply the SW_HIDE value ?!?!

That smells like a bug to me! Are you using the current service packs for Delphi 5? I haven't kept track of the changes that were made that long ago, but I suspect that you might have found a problem that was fixed in a service pack.

-PatP
Hi PatP,

this solve my problem already, thank you very much!!!!
Reply With Quote
  #14 (permalink)  
Old 03-29-04, 08:17
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
Oh, you just gotta love it when a plan comes together! I'm glad that we've finally managed to beat this problem into submission for you!

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On