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

Getting Local server's Time/Date!!!

Status
Not open for further replies.

WETFOX

Programmer
Jun 23, 2002
61
SA
Any expert here who knows how to capture local server time?
Our computer system here is always out of synch with our official time. I want to make a simple program from VB but my problem is how can I get our server's time so that I can synchronize it with erroneous computer here. Pls dont advise me of sending it to repair shop or buy a new one.
How can I manipulate our server's IP address or anything of related solution...PLSSS?????!!! Thanks for your hitech-tips.
ERA
era@nittsu.com.ph
era@digitelone.com
 
try this:

Dim MyDate As String
Dim MyTime As String

MyDate = #8/20/2002#
MyTime = #4:35:17 PM#

Date = MyDate
Time = MyTime


'this will set your server date and time to Aug 20, 2000 4:35:17 PM

 
Unfortunately that will only set local time, not server.

Have you tried faq1065 from chiph Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Unfortunately that will only set local time, not server.

Have you tried faq222-1065 from chiph Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 

check out these API's

NetRemoteTOD
CopyTimeValue
NetApiBufferFree

Good Luck
 
Thanks guys for suggestions!
However I want to clarify things that I want done:

My client PC always displays wrong time. Now I want to create small program that is always active checking our server time/date against client own time. If my program found out that the client PC displays wrong time, it will synchronize it with the server. My program will be installed
of course to the erroneous client PC.

@johnwm: the suggestion at FAQ... is too technical and very hard to code (for me) and i dont want to connect to time server where I dont have the control. Any more suggestions Sir?

@vb5prgrmr: i'm new to API but I'll try...

@jmerencilla: Sir can you have other solutions?

Thanks guys for great ideas!



ERA
era@nittsu.com.ph
era@digitelone.com
 
This what I posted not long ago...

mkuan (Programmer) Jul 27, 2002
Try this out. It works in VB6.

========================================
Option Explicit

Private Declare Function NetRemoteTOD Lib "netapi32.dll" (ByVal server As String, buffer As Any) As Long
Private Declare Function NetApiBufferFree Lib "netapi32.dll" (ByVal buffer As Long) As Long
Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Private Type TIME_OF_DAY
t_elapsedt As Long
t_msecs As Long
t_hours As Long
t_mins As Long
t_secs As Long
t_hunds As Long
t_timezone As Long
t_tinterval As Long
t_day As Long
t_month As Long
t_year As Long
t_weekday As Long
End Type

Private Sub Command1_Click()
Dim t As TIME_OF_DAY, tPtr As Long, res As Long, szServer As String, days As Date, todays As Date

szServer = "servername" ' replace this with the name of your server.
res = NetRemoteTOD(szServer, tPtr) 'You could also pass vbNullString for the server name
If res = 0 Then
CopyMemory t, ByVal tPtr, Len(t) 'Copy the pointer returned to a TIME_OF_DAY structure
days = DateSerial(70, 1, 1) + (t.t_elapsedt / 60 / 60 / 24) 'Convert the elapsed time since 1/1/70 to a date
days = days - (t.t_timezone / 60 / 24) 'Adjust for TimeZone differences
MsgBox days

NetApiBufferFree (tPtr) 'Free the memory at the pointer
End If

End Sub

======================================

This should do the trick.


Min.
 
Hello mkuan!

Thanks for giving me the exact code. But did you encounter
the problem stated:

"Can't find DLL entry point netremoteTOD in netapi32.dll"

in line:

res = NetRemoteTOD(szServer, tPtr)

Thanks again. ERA
era@nittsu.com.ph
era@digitelone.com
 
Follow up comment:

I think the code is applicable only for the NT Server and NT
workstation and Microsoft has not added a function "netremoteTOD" in netapi32.dll for non-NT machine.

Sad to say, the machine I am using right now to
make code is Win ME!!!

Do you have a workaround here???!!!
Thanks a lot!!! ERA
era@nittsu.com.ph
era@digitelone.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top