Back to Blog
Arnošt Havelka

Variables and Time

Use environment variables and time commands to build predictable automation and timestamped logs.

Start Interactive Lesson
Variables and Time

Variables and Time

Variables and timestamps are the backbone of maintainable batch workflows. Without them, scripts hardcode paths, logs become inconsistent, and debugging gets painful.

Core Idea

Use variables for values that change between machines or runs, and use time values to stamp outputs so every run is traceable.

Usage:set
LOG_DIR
=
C:\\Logs
&& echo %DATE% %TIME%
set NAME=value
Create/update variable for current shell session.
%NAME%
Resolve the variable value in commands.
%DATE% %TIME%
Emit execution timestamp for logs and reports.

Step 1: Read Existing Environment Values

Command Prompt
C:\Users\User>echo %PATH%

This confirms what executables your session can find without full paths.

Step 2: Build a Timestamped Log Entry

Command Prompt
C:\Users\User>echo Backup started at %DATE% %TIME% >> backup.log

Appending date/time entries makes audits and rollback investigations much faster.

Reliable Pattern

This single pattern greatly improves script portability and incident traceability.

References

These Microsoft Learn and Windows documentation links provide authoritative details for the commands used in this article.

Up Next

Services and Tasks

Learn reliable service triage and scheduled task checks for routine system administration.