|
-
May 1st, 2008, 07:46 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Server Time
I want to capture the time when someone logs in the app that I'm making. Now we all have admin access so the person can change the system time and then login making the Date function kinda redundant. Is there a way I can get the given computer's time? I searched around the web and found couple of code bases but these are like way too long to get this. Is there a simple way to do this or another alternative instead of taking the server time?
-
May 1st, 2008, 07:50 AM
#2
Re: Server Time
This is pretty straight forward
vb Code:
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
Dim tPtr As Long
Dim res As Long
Dim szServer As String
Dim days As Date
Dim todays As Date
' Replace \\ntsig with your NT server that you want to get the time from
szServer = StrConv("\\ntsig", vbUnicode) 'Convert the server name to unicode
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
'Get local computer information for comparison
todays = DateSerial(70, 1, 1) + (DateDiff("s", DateSerial(70, 1, 1), Now()) / 60 / 60 / 24)
Me.Cls
Print DateDiff("s", DateSerial(70, 1, 1), Now()), todays, t.t_elapsedt, days
NetApiBufferFree (tPtr) 'Free the memory at the pointer
Else
MsgBox "Error occurred Call NetRemoteTOD: " & res, vbOKOnly, "NetRemoteTOD"
'Error 53: cannot find server
End If
End Sub
-
May 1st, 2008, 07:50 AM
#3
Re: Server Time
Would something like this work for you? There are other samples available so check them all out.
-
May 1st, 2008, 07:51 AM
#4
Re: Server Time
BTW wussupbuddy.....what I posted and what RhinoBull posted is about as easy as it is going to get.
-
May 1st, 2008, 07:57 AM
#5
Thread Starter
Addicted Member
Re: Server Time
Any other workaround? My backend DB is hosted on the server, so I created a table with a date field defaulting to Date(). The problem with this was till the time the record is not created I can't fetch this single record and once this is saved then it becomes static. Is there a way to fetch the default value for a field which is not created yet?
-
May 1st, 2008, 07:58 AM
#6
Re: Server Time
 Originally Posted by wussupbuddy
Any other workaround? My backend DB is hosted on the server, so I created a table with a date field defaulting to Date(). The problem with this was till the time the record is not created I can't fetch this single record and once this is saved then it becomes static. Is there a way to fetch the default value for a field which is not created yet?
What does this have to do with getting the time on the server?
-
May 1st, 2008, 08:01 AM
#7
Thread Starter
Addicted Member
Re: Server Time
 Originally Posted by Hack
 What does this have to do with getting the time on the server?
My basic intention is to get current date..Thought of server time first sinve we can't change it..But since the code is so long, I thot I'll just get the Date() from the table hosted on the server.
-
May 1st, 2008, 08:02 AM
#8
Thread Starter
Addicted Member
-
May 1st, 2008, 08:20 AM
#9
Re: Server Time
The posted code is NOT long at all.
 Originally Posted by wussupbuddy
Is there a way to fetch the default value for a field which is not created yet?
Something which is not yet created does not have a value of any sort.
-
May 1st, 2008, 02:07 PM
#10
Re: Server Time
If you are using SQL Server you can use GetDate Function:
SQL Code:
SELECT CONVERT(CHAR(26), GETDATE(), 109)
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
May 1st, 2008, 10:02 PM
#11
Hyperactive Member
Re: Server Time
you can make a vb program that prevents the user from changing the date and time as well as detecting when it does.
its very simple to do
to detect time change add a sysinfo control
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|