×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Read or set time automatically in windows 10

Read or set time automatically in windows 10

Read or set time automatically in windows 10

(OP)
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

RE: Read or set time automatically in windows 10

>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
https://docs.microsoft.com/en-us/windows/win32/sys...
and
https://docs.microsoft.com/en-us/windows/win32/sys...

> 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

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close