Page 1 of 1

Get Server's Time() and Date()

Posted: Tue Jul 06, 2010 12:59 pm
by GeneB
Since the stations on our network occassionally have their time and date changed by a user, we had a need to get the time() and date() from the server for time stamping documents. A simple way to do it: create a file on the server, extract its time and date, erase the file.

Hope someone finds this useful.

GeneB in Albuquerque

Code: Select all

FUNCTION ServerTimeDate()
local  cTime,dDate, nHandle, aDirectory

// requires  Directry.ch
// DataPath() stores the path to the dbf files on the server
// file gets creation time and date from the server it resides on, DataPath()

FERASE( DataPath() + "\timefile.txt" )
nHandle := FCreate(DataPath() + "\timefile.txt")

// get the file's date and time
IF nHandle > 0
   aDirectory := DIRECTORY ( DataPath() + "\timefile.txt" )
   dDate := aDirectory[1,F_CREATION_DATE]
   cTime := aDirectory[1,F_CREATION_TIME]
ELSE
   dDate := DATE()
   cTime := TIME()
ENDIF

FCLOSE(nHandle)
FERASE( DataPath() + "\timefile.txt" )

RETURN {cTime,dDate}


Re: Get Server's Time() and Date()

Posted: Wed Jul 07, 2010 8:48 am
by rdonnay
Thanks Gene.

We all appreciate user contributions like this.