Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2004
    Posts
    36

    Unhappy Unanswered: 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.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    What OS / Database Engine does the server run? What OS / programming language does the client run?

    -PatP

  3. #3
    Join Date
    Mar 2004
    Posts
    36
    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

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

  5. #5
    Join Date
    Mar 2004
    Posts
    36
    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.

  6. #6
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

  7. #7
    Join Date
    Mar 2004
    Posts
    36
    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.

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    What programming language are you using? For example in VB you could use the Shell() function to run the NET command.

    -PatP

  9. #9
    Join Date
    Mar 2004
    Posts
    36
    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

  10. #10
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd run the NET command using Delphi's ShellAPI to avoid the complications of batch files, etc.

    -PatP

  11. #11
    Join Date
    Mar 2004
    Posts
    36
    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

  12. #12
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

  13. #13
    Join Date
    Mar 2004
    Posts
    36
    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!!!!

  14. #14
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •