Windows-10 batchfiles are based on DATE command, how to use on lower Windows versions
Solution 1
What a mess, but I believe I've found a solution for the issue:
The point is the following: On Windows 10, even while having a simple date format (like dd.MM.yyyy
), the date /T
commandline adds the first characters of the day, so we get the following:
date /T
st 22.03.2017
And my collegues have built their batchfiles around the presence of those "st" characters. Running those batchfiles on lower Windows versions gives the mentioned problems.
At the beginning of the batchfiles, I've added the line:
DATE=xx %DATE%
(very childish, I admit)
This makes the batchfiles work on my Windows-7 computer.
In order to make it work on both systems, I just need to add a check on the platform, something like:
set WINDOWS_10=%ver | findstr /C:"Version 10"%
if "WINDOWS_10"=="" (
set DATE=xx %DATE%)
I didn't check it yet on Windows-10 PC, but I believe this will do the trick.
Solution 2
In windows 7 you must use ddd
to have a similar format, which is 3 characters, not 2.
So you can use ddd dd.MM.yyyy. That's the supported format.
A way to get to 2 chars there would be to remove one with a batch file.
Related videos on Youtube
![Dominique](https://i.stack.imgur.com/Gve3F.png?s=256&g=1)
Comments
-
Dominique almost 2 years
I'm working on two (virtual) machines:
- First is a Windows 10 machine
- Second is a Windows 7 machine
On both, the short date formats are equal:
dd.MM.yyyy
On both, I'm running the same batchfile, based on theDATE
command.I'm having differences in the results, related to the outcome of the
DATE
command results:- On Windows 10 :
The current date is: st 22.03.2017
- On Windows 7 :
The current date is: 22.03.2017
As you can see, the difference is due to the presence of the name of today (
st
is an abbreviation of the Czech word forWednesday
).The Windows 10 system is the master, so my question: how can I alter the Windows-7 system to include the first two letters of the name of the day?
As tests, I've already tried the following for a short date format:
dd dd.MM.yyyy // this is better, the length of the format is good, but it does not start with the initials of the day's name. dddd dd.MM.yyyy // this starts with the day's name, but completely, and I only want the first two letters.
Meanwhile I had a further look at the problem: the date format seems to be used on two places:
- While working with the
DATE
commandline command (there I need a format likexx dd.MM.yyyy
(whatever thatxx
might be) for further processing - During following
echo
:for /r %DIRECTORY% %I in ("*.*") do echo %~tfI
The idea is to show a timestamp and the filename, something like:
22.03.2016 13:50 <filename>
(withoutxx
)
-
DavidPostill over 7 yearsPlease read the question again carefully. Your answer does not answer the original question. He want's to add to the Windows 7 machine not remove from the Windows 10 machine.
-
Overmind over 7 yearsLooks like the requirement is the other way around. I have updated.
-
Dominique over 7 yearsMaybe this might be helpful after all: do you have any idea how somebody managed to get it done on Windows 10? Short date format:
dd.MM.yyyy
DATE commandline result :st 22.03.2017
=> How did they manage getting this result starting withst
? -
AFH over 7 yearsI can't check Win7 any more, as I upgraded all my W7 systems, but on Win10 your
set Windows_10=
command doesn't work: you needver | findstr /C:"Version 10"
, followed byif errorlevel 1 set DATE=xx %DATE%
. This will affect what%DATE%
returns, but thedate
command itself will be unaffected. You should alsoset DATE=
first, to remove the local variable, and again before exit, so as not to affect other batch files called from the samecmd
instance. -
Overmind over 7 yearsYou will have no st if you only modify it to dd.MM.yyyy. To re-add the st, re-set must be in dd dd.MM.yyyy format.
-
Overmind over 7 yearsIt does not add them if you altered your settings.
-
Dominique about 7 years@AFH: thanks for the warning, but the batchfiles are to be used from the task scheduler, so there will never be any other programs to be run from the same
cmd
instance.