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

Get time from server not workstation

Status
Not open for further replies.

priac

Technical User
Feb 8, 2002
47
US
I have an Access program that records the IP address, username, and time "now()", when you enter the program. My problem is that we work in several time zones. Is there a way of getting the time from a singleplace. The program is on a server in Germany. How would I tell "now()" to use the time from "\\dataserver1".
 
How about using Getdate() instead of Now()? GetDate should return the server's local date and time I believe.

Dave

 
I'm having the exact same problem. I need to log a date and time when users do certain things and I have a problem with them changing their system time on their local machines. The server is upstairs with me, so I know the time will always be right. I need to record the time and date from the server. Any ideas??
 
I am not going to take the credit for this, because i didnt write it, but here it is, im sure Dev Ashish wont mind

;-)

'*************** Code Start ****************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Type TIME_OF_DAY_INFO
tod_elapsedt As Long 'the number of seconds _
since 00:00:00, January 1, 1970.
tod_msecs As Long 'the number of milliseconds _
from an arbitrary starting point _
(system reset).
tod_hours As Long 'current hour (0-23)
tod_mins As Long 'current minute (0-59)
tod_secs As Long 'current second (0-59)
tod_hunds As Long 'the current hundredth second (0-99).
tod_timezone As Long 'TZ of Server in Minutes from GMT
tod_tinterval As Long 'time interval for each tick of the _
clock. Each integral integer _
represents one ten-thousandth _
second (0.0001 second).
tod_day As Long 'the day of the month (1-31).
tod_month As Long 'the month of the year (1-12).
tod_year As Long 'Specifies the year.
tod_weekday As Long 'the day of the week; 0 is Sunday
End Type

Private Declare Function apiNetRemoteTOD Lib "netapi32" _
Alias "NetRemoteTOD" _
(ByVal UncServerName As String, _
BufferPtr As Long) _
As Long

Private Declare Sub sapiCopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)

Public Function fGetServerTime(ByVal strServer As String) As String
'*******************************************
'Name: fGetServerTime [NT ONLY] (Function)
'Purpose: Returns Time of Day for NT Server
'Author: Dev Ashish
'Date: Monday, January 11, 1999
'Called by: Any
'Calls: NetRemoteTOD, RtlMoveMemory
'Inputs: Name of NT Server in \\ServerName format
'Returns: Time of day for the NT Server
'*******************************************
On Error GoTo ErrHandler
Dim tSvrTime As TIME_OF_DAY_INFO, lngRet As Long
Dim lngPtr As Long
Dim strOut As String
Dim intHoursDiff As Integer
Dim intMinsDiff As Integer

If Not Left$(strServer, 2) = "\\" Then _
Err.Raise vbObjectError + 5000

strServer = StrConv(strServer, vbUnicode)
lngRet = apiNetRemoteTOD(strServer, lngPtr)
If Not lngRet = 0 Then Err.Raise vbObjectError + 5001
Call sapiCopyMemory(tSvrTime, ByVal lngPtr, Len(tSvrTime))

With tSvrTime
intHoursDiff = .tod_timezone \ 60
intMinsDiff = .tod_timezone Mod 60
strOut = .tod_month & "/" & .tod_day & "/" _
& .tod_year & " "
If .tod_hours > 12 Then
strOut = strOut & Format(.tod_hours - 12 - intHoursDiff, "00") _
& ":" & Format$(.tod_mins - intMinsDiff, "00") & ":" _
& Format$(.tod_secs, "00") & " PM"
Else
strOut = strOut & Format(.tod_hours - intHoursDiff, "00") _
& ":" & Format$(.tod_mins - intMinsDiff, "00") & ":" _
& Format$(.tod_secs, "00") & " AM"
End If
End With
fGetServerTime = strOut
ExitHere:
Exit Function
ErrHandler:
fGetServerTime = vbNullString
Resume ExitHere
End Function
'**************** Code End *****************
 
The code that you gave does work, except that the time is like 6 hours ahead. Is there something that you have to adjust with the Time Zone or something. I understand that the code is for an NT machine, but what is the API call you have to make for a Windows 98 or Windows ME machine? That would really be a huge help for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top