[RESOLVED] Anything wrong with this code?
Code:
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Sub Command1_Click()
Dim SystemStartTimeDate As Data
Ddayticked = timeGetTime / 1000 / 60 / 60 / 24 'min
MsgBox DateValue(Now() - Ddayticked)
MsgBox TimeValue(Now() - Ddayticked)
End Sub
the above will retrive the system started time and date.
but it seems systems started before 25 or so shows incorrect system started date and its a feature date ex 10/15/2009 according to one of my client bug report :mad:
screen shots :
This is correct. it was taken using a 3rd party tool
http://img40.imageshack.us/img40/6374/screenshotmj.jpg
but,
for the same, my above code shows
system started date 10/13/2009 time: 3/18/34 http://www.vbforums.com/
any problem with above code?
Re: Anything wrong with this code?
Try this instead:
Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Sub Form_Load()
Dim myStartTime As Long
myStartTime = timeGetTime / 1000
Debug.Print DateAdd("s", -myStartTime, Now)
End Sub
Re: Anything wrong with this code?
Quote:
Originally Posted by
RhinoBull
Try this instead:
Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Sub Form_Load()
Dim myStartTime As Long
myStartTime = timeGetTime / 1000
Debug.Print DateAdd("s", -myStartTime, Now)
End Sub
rinobull,
yah your one also works correct in my pc which booted just 2 hours ago.
ill send this code as exe to my client whos computer started before 25 days ago and bring the result.
Re: Anything wrong with this code?
Note that timeGetTime and GetTickCount and possibly other windows timing APIs will reset after a pc has been on continuously for approximately 50 days. The value may also be negative if => 2^31 (return value is signed whereas unsigned within the O/S).
Quote:
Originally Posted by msdn
Note that the value returned by the timeGetTime function is a DWORD value. The return value wraps around to 0 every 2^32 milliseconds, which is about 49.71 days.
Source page
Edited: You mentioned 25 days as a marker. Look at this:
The max positive value of a Long is: 2147483647 (approx 24.855 days)
The nr of ms for 25 days is: 2160000000 (assuming I did my math correctly)
This means that I would expect the return value form timeGetTime to be a negative value (unsigned "Long" value converted to signed)
Re: Anything wrong with this code?
Quote:
Originally Posted by
LaVolpe
Note that timeGetTime and GetTickCount and possibly other windows timing APIs will reset after a pc has been on continuously for approximately 50 days. The value may also be negative if => 2^31 (return value is signed whereas unsigned within the O/S).
Source page
Edited: You mentioned 25 days as a marker. Look at this:
The max positive value of a Long is: 2147483647 (approx 24.855 days)
The nr of ms for 25 days is: 2160000000 (assuming I did my math correctly)
This means that I would expect the return value form timeGetTime to be a negative value (unsigned "Long" value converted to signed)
yes volp, i was aware of that 49days max limit by this function ;)
btw,
if i am correct,
in
myStartTime = timeGetTime / 1000
&
Ddayticked = timeGetTime / 1000 / 60 / 60 / 24 'min
the left most variables never get numbers in milli seconds. either in seconds or in hours or even days.
according my little math or programming knowledge :bigyello:
so no problem of declaring it as long.
for 25 days you get 2160000 seconds only right.
Re: Anything wrong with this code?
Quote:
Originally Posted by
Fazi
... for 25 days you get 2160000 seconds only right.
No. The value of timeGetTime starts at negative as returned from the API, if more than 24.855 days since last booted. I would convert signed to unsigned (which will be a double) then divide by 1000.
Re: Anything wrong with this code?
Quote:
Originally Posted by
LaVolpe
No. The value of timeGetTime starts at negative as returned from the API, if more than 24.855 days since last booted. I would convert signed to unsigned (which will be a double) then divide by 1000.
undestood :)