0

I'm trying to interpret a former colleague's script that is failing.

It has the following syntax:

set CREATIONDATE=%date:~-4%%date:~3,2%%date:~0,2%

I think this is intended to be 'today's date' in some fashion.

On my machine this returns '2019 0Tu'. Seems like garbage.

This colleague worked in Germany. I work in the United States. I wonder if the date format mismatches or regional settings play a part here. Can some explain what the above attempts to do?

user45867
  • 887
  • 2
  • 17
  • 30
  • What language/shell is the script in? – Katharine Osborne Apr 16 '19 at 17:16
  • 1
    I believe this is directly in Windows command line --- I'm not the expert obviously. 'cmd' or Run 'cmd' -- the command line interface – user45867 Apr 16 '19 at 17:17
  • It's parsing the results of %date% (a built-in pseudo-environment variable) to pick out parts of the date, most likely looking for something like `2019-04-16`. It's broken because of the different default date format (it's regional). Adjust it to fit yours;you can see how yours is set by typing `echo %date%` from a command prompt. – Ken White Apr 16 '19 at 17:17
  • @user45867 this might be somewhat helpful: https://stackoverflow.com/questions/1192476/format-date-and-time-in-a-windows-batch-script – Katharine Osborne Apr 16 '19 at 17:20
  • Alright I figured this out. Someone could have told me that the above arguments are basically substring arguments of sorts. It attempted to take the last 4 digits (typically year) -- then the 3rd position, 2 chars (month in Germany) -- then first two characters (day in Germany typically) --- my date settings have Tues (day of week) first and break it all – user45867 Apr 16 '19 at 18:13

0 Answers0