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

Read or set time automatically in windows 10

Status
Not open for further replies.

Abakurd

Programmer
Oct 9, 2015
2
IQ
Hi;
Kindly your help, I want to read or set time automatically from window 10 if can use windows API or MS access VBA.
in fact I need to get the actual date even if anybody change date in the windows.
Thanks
 
>I need to get the actual date even if anybody change date in the windows.

Sorry, are you working under the assumption that Windows keeps track of some sort of 'actual date" as opposed to what it tells the user? This isn't true, I'm afraid. The RTC that Windows queries on startup contains current local time, which is converted to the correct UTC for the system's current time zone setting; and then maintained by the Windows system clock

The Windows system clock is then kept up to date via interrupts and also by access to either a domain time source or internet time source if time synch is enabled. It is converted back to local time and saved back to the RTC on a regular basis. Switching off time synch allows the user to change the time to anything that they like - but both the Windows system clock and the RTC will track those changes. In other words there is no clock with an 'actual date'

You might want to read
and

> read or set time automatically from window 10
That's what VBA's Time and Date function do ... although they provide the time in yopur local time zone. If what you are saying is you want the UTC (i.e uncorrected for local time), you can use the GetSystemTime and (if time synch is switched off and your session has the relevant privileges) SetSytemTime (or setLocalTime, or Time) to set it.

Assumiong what you are interested in is the UTC , the follwoing would work:

Code:
[blue]Option Compare Database
Option Explicit

Private Type SYSTEMTIME
    Year As Integer
    Month As Integer
    DayOfWeek As Integer
    Day As Integer
    Hour As Integer
    Minute As Integer
    Second As Integer
    Milliseconds As Integer
End Type

Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

Public Sub check()
    Dim st As SYSTEMTIME  
    GetSystemTime st
    MsgBox "UTC is: " & DateSerial(st.Year, st.Month, st.Day) & " " & TimeSerial(st.Hour, st.Minute, st.Second)
End Sub[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top