Question : Format of date command

In a batch-file that I'm using, there is an echo command containing the variable %date% to create a logfile (see attachment).
 I run this batch for  a lot of machines and every machine has its own format of date (see attachment).
Is there a way to fix this problem so I have all dates in the format dd/mm/yyyy.
Thanks
Attachments:
 
Example of command and output
 

Answer : Format of date command

Here's a fairly flexible approach that doesn't assume any particular format of the date on each system, but rather looks at the date format settings on that machine, and gets the month, day and year pieces of the date based on those.  They you can build your log date stamp from those pieces.

Let me know if you have any questions.

I'll mention one other item here too.   I have a small, freeware utility that I often use for these type of times stamps which works great regardless of the way a system has the date format configured.  But it is a small EXE that is needed.  Depending on your situation you may want to just stick with pure command line base commands, but wanted to pass it along in case it is useful at some point in the future.  It does a great job of getting current date / time, as well as getting dates in the past or future, offset by any number of days you want.  Check out DOFF at:

http://www.jfitz.com/dos/index.html#DOFF

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
@echo off
call :GetDate "Month" "Day" "Year"
echo %Month%/%Day%/%Year% - %time% - %computername% - %username% >>%SRCdisk%\Logs\LogInLog.txt
exit /b
 
:GetDate [month-variable] [day-variable] [year-variable]
  REM Get date format settings from registry
  rem For REG.EXE 3.0 (Windows XP) and later versions
  for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International" /v iDate 2^>NUL') do set "iDate=%%A"
  for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International" /v sDate 2^>NUL') do set "sDate=%%A"
  rem For earlier REG.EXE versions
  rem for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International\iDate" 2^>NUL') do set "iDate=%%A"
  rem for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International\sDate" 2^>NUL') do set "sDate=%%A"
 
  REM Get the current system date (ignore day name if present)
  for %%A in (%Date%) do set "Today=%%A"
 
  REM Parse current date based on delimiter from registry, and assign to desired user variable
  for /F "tokens=1-3 delims=%sDate%" %%A in ("%Today%") do (
    if "%iDate%"=="0" set "%~2=%%B" & set "%~1=%%A" & set "%~3=%%C"
    if "%iDate%"=="1" set "%~2=%%A" & set "%~1=%%B" & set "%~3=%%C"
    if "%iDate%"=="2" set "%~2=%%C" & set "%~1=%%B" & set "%~3=%%A"
  )
  exit /b
)
Random Solutions  
 
programming4us programming4us