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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving Date/Time from Server

Status
Not open for further replies.

ToddWW

Programmer
Mar 25, 2001
1,073
0
0
US
I need a client to get the system date and time from the server. I have tried using a stored procedure in the database server like this.

This is written in the stored procedure file on the database server.
Code:
PROCEDURE getServerTime(dbServerTime)
  dbServerTime = DATETIME()
  RETURN dbServerTime
END PROC

This is code from a program on the client machine.
Code:
OPEN DATABASE fbdata1.dbc
DO getServerTime WITH timeValue
CLOSE DATABASE
? timeValue

The procedure runs fine, however the value represents the date and time of the client, not the server where the stored procedure resides. Is there any way for a client machine to retrieve the system date/time from the database server ?

Thanks

ToddWW
 

Just create an textfile on the server with FCREATE() and get the datetime stampped on the file.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Hi Todd,

Even though a stored proc is in the DBC on the file server the code runs on the client. It's like putting an EXE on the file server and starting it on a LAN drive. That will also execute it on the client and return the client time.

The easiest way may really be creating a file with FCREATE() or even just simply STRTOFILE() and retrieving the filedate with FDATE(filename,1).

Bye, Olaf.
 
this function to help you:
Time1= Get_Server_Time("192.168.1.33")
?Time1
**************************************************
* Get server time:
* Server name may be Name of any computer on LAN
* or IP of any computer on LAN ...
**************************************************
FUNCTION Get_Server_Time
PARAMETERS _ServerName
PRIVATE _ServerName, cServerTime, ServerTime, _date
IF !AT("\\",_ServerName)=1
_ServerName= "\\"+_ServerName
ENDIF
RUN NET TIME &_ServerName > Result.TXT
cServerTime= FILETOSTR("Result.TXT")
_date= SET("DATE")
SET DATE TO AMER
ServerTime= CTOT(SUBSTR(cServerTime,AT("is",cServerTime)+3,18))
SET DATE TO &_date
RETURN ServerTime
 

Thuvan,

Just our of curiosity, have you ever run your code from within an EXE? The reason I ask is that I believe the following line might not work:

Code:
 RUN NET TIME &_ServerName > Result.TXT

A colleague of mine has been trying to do this recently, and just gets an empty text file. He says it works OK in the development environment, but not in a run-time app.

Any comments?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
I just have checked this function in EXE file.
1) The empty file Result.TXT might occur when wrong server name (wrong computer name).
2) Need a little corect:
ServerTime= CTOT(STRTRAN(SUBSTR(cServerTime,AT("is",cServerTime)+3,18),CHR(13),""))
to delete chr(13) on line 1 from Result.TXT
ThuVan

 

ThuVan,

Thanks for the clarification, but I don't think it applies in my friend's case. He is sure the correct server is being accessed, and there's no problem with the rest of the code.

He says that it is the DOS redirection that is not working in an EXE (that is, the ">" symbol, which sends the output to a text file).

Not to worry. It's just one of those strange problems ...

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
In all most DOS-version, the symbol ">" on dos-command line send result to text-file.
My computer with Windows-XP, VFP7; and this function (command line) is working normaly.
May be you explain your code that give wrong result?
Thanks
ThuVan
 

Thuvan,

It wasn't my code that gave the wrong result. This is all second hand. But as far as I know, the line of code was something like this:

NET TIME \\GJS >C:\TEMP\CURRTIME.TXT

It works fine if you run it at the DOS prompt, and also if you run it in VFP via the RUN command, but if you run it in an EXE via the RUN command, the text file is empty.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Oh! Mike,
that maybe your VFP run quickly, please add line:
RUN NET TIME \\GJS >C:\TEMP\CURRTIME.TXT
=INKEY(1, "H") &&Slow VFP down so windows can make the file first
MODIFY FILE C:\TEMP\CURRTIME.TXT

Thuvan
 
Hi Mike,

the difference may be what DOS promt is activated by RUN. Wasn't there some fox.pif file, which could either call command or cmd? How about writing a batch file with the dos command in it and start that with RUN?

And isn't it finally much easier to simply create a file on a LAN drive and read out FDATE(fname,1)?

Bye, Olaf.
 

Olaf,

You're right about the PIF issue, but I doubt it is relevant in this case. The point is that the DOS command runs OK -- it is just the redirection of the output to a text file that is failing.

I agree that it's easier to create a file on a LAN drive. But I was asked to help solve the particular problem of redirecting the DOS output, which is why I jumped into this thread.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Olaf,
NET TIME <Server Name> help you get time on any server
and resolve problem when you not have right to create file on server
ThuVan
 
I have found these code: to synchronize time of client with Server: just run on window200 or higher
IF OS() > 3 && IF PLATFORM IS WIN2000 OR HIGHER
myServerName = "YourSererName"
lcCmd = GETENV("ComSpec") + " /C NET TIME \\"+ myServerName+" /SET /YES"
loShell = CREATEOBJECT("wscript.shell")
loShell.Run(lcCmd,0,.t.)
ENDIF

Have Fun!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top