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

How to get the datetime() from VFP database server

Status
Not open for further replies.

dejanj

Programmer
Apr 22, 2002
25
AU
Is there a way to get the current datetime() from the Visual FoxPro database
Hi All,

Is there a way to get the current datetime() from the Visual FoxPro database server.
I have a client talking via ODBC to Visual FoxPro DBC on the network (
Client/Server app designed in Visual FoxPro 7... backend is Visual FoxPro DBC).
When i create a record using Client i would like to stamp it NOT with
DATETIME() from the CLient PC but with datetime() from the Visual FoxPro
server ( server PC ).

Can you help?

Regards
Dejan Jocic
Sydney, Australia
 
HI Dejan,

1. Create an offset - the difference between the server time and the Client's time at the beginning. (This to avoid repetitive work and the performance involved.
2. Then use this offset to find the server time everytime you want.. by using Clents TIme+OFFSET and obtain the DateTime value for server equivalent.

The method to get server time as said in (1) above can be..

Create a temporary file on server file, read the date and time of that file and make the difference with the client time.

FUNCTION ServerTime
LPARAMETERS vcServerPath

LOCAL LcFileName, LnHandle, ltReturn

LcFileName = ADDBS(vcServerPath) + SYS(2015) + ".TMP"

LnHandle = FCREATE(lcFileName, 0)

IF ADIR(laDir, lcFileName)>0
ltReturn = CTOT(DTOC(laDir[1.3] + " " + laDir[1,4]))
ENDIF

ERASE (lcFileName)

RETURN ltReturn
********************************************

3. I have heard about APIs such as RemoteTOD() for NT, but these get restricted by the OS and Server OS.

You can find API call RemoteTOD() in the MSDN Platform SDK. It is only applicable to NT, Win2K and Win XP client systems, and requires an NT or Win2K server as a target to implement.

I have not used and I dont remeber where I got this code from... Credit to the concerned person...

"
NetRemoteTOD
The NetRemoteTOD function returns the time of day information from a specified server.

Security Requirements
No special group membership is required to successfully execute the NetRemoteTOD function.

NET_API_STATUS NetRemoteTOD(
LPCWSTR UncServerName,
LPBYTE *BufferPtr
);
Parameters
UncServerName
[in] Pointer to a constant Unicode string specifying the name of the remote server on which the function is to execute. The string must begin with \\. If this parameter is NULL, the local computer is used.
BufferPtr
[out] Pointer to the address that receives the TIME_OF_DAY_INFO information structure. This buffer is allocated by the system and must be freed using the NetApiBufferFree function
" .....
The above is a copy from my tips database.

Hope this helps you solve your problem :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Dejan,
Another alternative would be to have the VFP database designer include a stored procedure to provide this functionality. While you can't use ODBC to directly get to the stored procedures, you can use the VFP 7.0 OLEDB provider - it can.

Rick
 
dejanj:

I don't know how your server app is setup, but as rgbean alludes to, the server can stamp it from a stored procedure.

That way you don't even incur the network traffic in retrieving the server's datetime().

Otherwise, if don't have control of the server app, ramani's post is on the right track.

Darrell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top