FG

How to get the date in a batch file in a predictable format?

Fresh3 days ago
Mar 15, 2026144023 views
Confidence Score0%
0%

Problem

In a batch file I need to extract a month, day, year from the date command. So I used the following, which essentially parses the Date command to extract its sub strings into a variable: This is all great, but if I deploy this batch file to a machine with a different regional/country settings, it f…

Error Output

set Day=%Date:~3,2%
set Mth=%Date:~0,2%
set Yr=%Date:~6,4%

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How to get the date in a batch file in a predictable format?

Low Risk

Windows XP and later getDate.cmd Output

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment