2

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)
  • It's not possible to have 2 character weekdays in Windows 7. – DavidPostill Mar 22 '17 at 12:39
  • I see two choices: (1) use long day format, but change the day names to their short equivalents, though this means that you will never see the true long day names; (2) write your own program to report the date: this would be only a few lines of C, and will be completely independent of regional settings, or it could be done in a somewhat complex batch file which manipulates the contents of the `%DATE% variable. – AFH Mar 22 '17 at 13:02
  • Use wmic or PowerShell to manipulate the date in a Locale, Regional, and Language settings independent way. See my answer Batch script (cmd) resulting in DD-MM-YYYY_weekday format for some tips. – DavidPostill Mar 22 '17 at 13:22
  • @AFH: unfortunately even writing an own little program does not solve the issue: I would need to call this program "date.exe", but when I launch Date, even in the directory where I've just compiled "date.exe", it still keeps on taking the commandline DATE command instead. – Dominique Mar 22 '17 at 14:42
  • Why do you need to give it the same name? Why not call it CzDate.exe or something similar? In cmd the date command is a shell built-in, so will always be chosen in preference to an external date.exe, unless you add a path to the call, eg .\date; alternatively, for command-line use (not in a batch file) you can set an alias, eg doskey date=.\date.exe. – AFH Mar 22 '17 at 15:39
1

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.

  • 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. – DavidPostill Mar 22 '17 at 12:32
  • Looks like the requirement is the other way around. I have updated. – Overmind Mar 22 '17 at 13:17
  • 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 ? – Dominique Mar 22 '17 at 13:22
  • 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 Mar 23 '17 at 7:02
0

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.

  • 1
    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. – AFH Mar 22 '17 at 17:49
  • It does not add them if you altered your settings. – Overmind Mar 23 '17 at 7:03
  • @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. – Dominique Mar 29 '17 at 9:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.