Sync date & time from command line / batch file

Abstract: Resolve system clock drift and ensure accurate logging by forcing Windows Time Service synchronization via w32tm or manually setting time using command line tools.

Created: 2026-08-22 by
To synchronize the system date and time from a command line or batch file, use the built-in w32tm utility for network-based synchronization or the time and date commands for manual adjustments. For immediate updates without rebooting, run w32tm /resync to force an interaction with the configured Windows Time service. These methods ensure your system clock remains accurate for logging, authentication, and scheduled tasks.

Using w32tm for Network Synchronization

The most reliable way to sync your computer's clock is by using the Windows Time Service (W32Time). This service communicates with external time servers over the internet or your local network domain controllers. The primary tool for managing this service via the command line is w32tm. First, verify that the service is running correctly. Open a Command Prompt as an administrator and execute:
w32tm /query /status
This command displays the current time source, stratum level, and last successful synchronization time. If the status indicates an error or shows that the service is stopped, you may need to restart it using:
net stop w32time
net start w32time
Once the service is active, you can force an immediate synchronization with the configured time server by running:
w32tm /resync
If you receive an error message such as "The client was unable to synchronize up with the time source," check your network connectivity to the time server or adjust the registry settings if your organization uses a specific internal NTP server. You can also specify a custom server directly in the command:
w32tm /config /syncfromflags:manual /manualpeerlist:"pool.ntp.org" /update
w32tm /resync
This approach is ideal for environments where automatic background syncing might be delayed or blocked by firewall rules. It provides explicit control over when the update occurs.

Manual Date and Time Adjustment

In scenarios where network access is unavailable or you need to set a specific timestamp for testing purposes, you can manually set the date and time using native Windows commands. This method does not require internet connectivity but requires administrative privileges. To change the time, use the time command followed by the desired value in HH:MM:SS format:
time 14:30:00
You will be prompted to confirm the new time. Press Enter to accept. To change the date, use the date command followed by the date in MM-DD-YYYY format:
date 05-15-2024
Again, press Enter to confirm. While these commands are simple, they do not account for leap seconds or drift correction provided by NTP services. They are best used for temporary adjustments or offline systems. For more complex automation, you might need to parse text files containing timestamps. Understanding how to handle delimiters can help when extracting time data from logs. See How to Parse a Text File and Delimit with Colon Character in a Batch File for techniques on handling structured data in scripts.

Creating a Batch File for Automation

To automate this process, create a batch file (.bat) that executes the synchronization commands. This is useful for startup scripts or scheduled tasks that run periodically. Create a new text file named sync_time.bat and add the following lines:
@echo off
echo Syncing time...
w32tm /resync
if %errorlevel% equ 0 (
    echo Synchronization successful.
) else (
    echo Synchronization failed. Check network or service status.
)
Save the file and double-click it to run. Ensure you run it with administrator rights, either by right-clicking and selecting "Run as administrator" or configuring a scheduled task with elevated privileges. Customizing the appearance of such batch files can improve user experience, especially if they are shared with non-technical users. Learn about Learn Making: Customizing the Visual Appearance of Your .app.bat File to make your scripts more professional and readable.

Scheduled Tasks for Regular Syncs

Instead of relying on the default Windows Time Service intervals, you can create a scheduled task to force synchronization at specific times. Open Task Scheduler and create a new task. Set the trigger to your preferred frequency (e.g., daily at noon). In the action section, choose "Start a program" and enter w32tm.exe with the argument /resync. This ensures that even if the background service fails, your clock will be corrected regularly. This is particularly important for financial applications or security protocols that rely on precise timestamps.

Troubleshooting Common Issues

If synchronization fails, consider the following steps:
  • Firewall Blocks: Ensure UDP port 123 is open for NTP traffic.
  • Service Disabled: Check Services.msc to ensure Windows Time is set to Automatic.
  • Registry Keys: Verify HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters\NtpServer contains a valid server address.
  • Virtual Machines: VMs often struggle with time sync due to host-guest interactions. Disable "Synchronize guest time with host" in VM settings if using w32tm.

Frequently Asked Questions

Can I sync time without internet access?

Yes, you can manually set the time using the time and date commands, or sync with an internal local NTP server if one exists on your LAN. Network-based syncing requires connectivity to a time source.

Why does w32tm /resync fail with error 0x800704DD?

This error typically indicates that the Windows Time service is not running or lacks sufficient permissions. Restart the service using net start w32time and ensure you are running the command prompt as an administrator.

How do I check which time server my PC is using?

Run w32tm /query /source in the command line. This will display the name of the NTP server currently being used for synchronization, helping you verify configuration accuracy.

Is it safe to disable the Windows Time Service?

Disabling the service prevents automatic synchronization, leading to potential clock drift over time. This can cause issues with certificate validation, file versioning, and domain authentication. It is generally recommended to keep it enabled.

Can I use PowerShell instead of CMD for this task?

Yes, PowerShell can execute the same w32tm commands. You can also use Get-Date to view the current time and Set-Date to manually adjust it programmatically within scripts.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More