The date format/layout/strings in the variable %date%
changes as: region, language and/or settings made by the user:
The variable %date%
will always display the date in the format according language & country, or in a custom/user configured format, ie does not follow fixed layout/default, where we can work in a predictive way, and consequently manipulate the output string, relying on a fixed/predictable layout
I suggest using the wmic.exe
, where, safely, you have a standardized and independent output of any region, language and/or any settings made by the user.
Using the wmic.exe
to get the date in a reliable layout/format, where the user, language or region settings do not undergo any change...
References:
- Alternative to compose date layout picking month/day with zero when less/equal 9:
set "filedatetime=!_day!-!_Month!-!_year!"
set "filedatetime=!_Month!/!_day!/!_year!"
set "filedatetime=!_year!-!_Month!-!_day!"
set "filedatetime=!_day!!_Month!!_year!"
set "filedatetime=!_Month!!_day!!_year!"
set "filedatetime=!_year!!_Month!!_day!"
- Example using zero for
mês/dia >=9
and also picking up/setting the variables Year, Month
and Day
separately to assemble the desired date layout:
wmic.exe Path Win32_LocalTime Get Year,Month,Day
Porting to the bat/cmd:
@echo off && setlocal EnableDelayedExpansion
@%__APPDIR__%mode.com con:cols=60 lines=8
title <nul & title Add Send Versionamento
for %%i in (Year,Month,Day)do for /f %%I in ('
%__APPDIR__%wbem\wmic.exe Path Win32_LocalTime Get "%%~i"^|%__APPDIR__%findstr.exe [0-9]
')do if not "%%~i"=="Year" (set "_%%~i=0%%~I" && call set "_%%~i=!_%%~i:~-2!") else set "_%%~i=%%~I"
rem :: Obs.: Invertendo a data e usando zero: ano/ 0+mês/ 0+dia, ::
rem :: Vai obter um mesmo número de dígitos e sempre crescente. ::
set "filedatetime=!_year!!_Month!!_day!"
cd /d "C:\xampp\htdocs\laravelapi"
:loop
echo/ & set /p "_message="Digite Mensagem: "
echo/!_message!|%__APPDIR__%findstr.exe [a-Z] >nul || cls && goto :loop
cmd.exe /v /c git add .
cmd.exe /v /c git commit -m "!_message! Ref: !filedatetime!/%username%"
cmd.exe /v /c git push
%__APPDIR__%timeout.exe -1 & endlocal && goto :EOF
For input: Versão de !date!
Commando: git commit -m "!_message! Ref: !filedatetime!/%username%"
, Results:
"Versão de 2020-02-19 Ref: 20200219/ecker"
Obs.:
set /p
does not return any indication stating that the user has entered a set of characters,or the Enter only, where, some additional commands are can be used to check whether the input (variable: !_message!
) has actually received value/characters....
Taking the date in a predictive format, in predictable and reliable layout
Obtains looping inputs, which will verify the presence or not of characters
Prevents execution of next commands when input is null/character free
Stay looped if user does not type anything and/or just press ENTER
@echo off && setlocal EnableDelayedExpansion
@%__APPDIR__%mode.com con:cols=60 lines=8
title <nul & title Add Send Versionamento
cd /d "C:\xampp\htdocs\laravelapi"
for /f "tokens=2delims==." %%i in (
'%__APPDIR__%\wbem\wmic.exe OS Get localdatetime /value^|findstr [0-9]'
) do set "_d=%%i" && call set "filedatetime=!_d:~6,2!!_d:~4,2!!_d:~0,4!
echo/ Data Layout : !_d:~6,2!/!_d:~4,2!/!_d:~0,4!- !_d:~8,2!:!_d:~10,2!]
:loop
echo/ & set /p "_message="Digite Mensagem: "
echo/!_message!|%__APPDIR__%findstr.exe [a-Z] >nul || cls && goto :loop
cmd.exe /v /c git add .
cmd.exe /v /c git commit -m "!_message! Ref: !filedatetime!/%username%"
cmd.exe /v /c git push
%__APPDIR__%timeout.exe -1 & endlocal & goto :EOF
- Or with a hybrid input box with VBS:
<!-- ::
@%__APPDIR__%mode.com con:cols=60 lines=8
@echo off && setlocal EnableDelayedExpansion
title <nul & title Add Send Versionamento
cd /d "C:\xampp\htdocs\laravelapi"
for /f "tokens=2delims==." %%i in (
'%__APPDIR__%\wbem\wmic.exe OS Get localdatetime /value^|findstr [0-9]'
) do set "_d=%%i" && call set "filedatetime=!_d:~6,2!!_d:~4,2!!_d:~0,4!
echo/ Data Layout : !_d:~6,2!/!_d:~4,2!/!_d:~0,4!- !_d:~8,2!:!_d:~10,2!
:loop
for /f "tokens=*delims= " %%i in ('%__APPDIR__%CScript.exe //NoLogo "%~f0?.wsf"')do set "_message=%%~i"
echo/!_message!|%__APPDIR__%findstr.exe [a-Z] >nul || goto :loop
cmd.exe /v /c git add .
cmd.exe /v /c git commit -m "!_message! Ref: !filedatetime!/%username%"
cmd.exe /v /c git push
%__APPDIR__%timeout.exe -1 & endlocal & goto :EOF
# --><job><script language="vbscript">
Input=InputBox("Digite Mensagem: ", "Novo Versionamento: "): wsh.echo Input: Set Input=Nothing
</script></job>
vlw man, you really helped!
– Luiz Roberto Furtuna