Windows-10 batchfiles are based on DATE command, how to use on lower Windows versions

5,051

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.

Share:
5,051

Related videos on Youtube

Dominique
Author by

Dominique

Too much to say :-)

Updated on September 18, 2022

Comments

  • Dominique
    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 the DATE 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 for Wednesday).

    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:

    1. While working with the DATE commandline command (there I need a format like
      xx dd.MM.yyyy (whatever that xx might be) for further processing
    2. 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> (without xx)
  • DavidPostill
    DavidPostill over 7 years
    Please 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
    Overmind over 7 years
    Looks like the requirement is the other way around. I have updated.
  • Dominique
    Dominique over 7 years
    Maybe 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 with st ?
  • AFH
    AFH over 7 years
    I 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 need ver | findstr /C:"Version 10", followed by if errorlevel 1 set DATE=xx %DATE%. This will affect what %DATE% returns, but the date command itself will be unaffected. You should also set DATE= first, to remove the local variable, and again before exit, so as not to affect other batch files called from the same cmd instance.
  • Overmind
    Overmind over 7 years
    You 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
    Overmind over 7 years
    It does not add them if you altered your settings.
  • Dominique
    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.