# Solved: Rename File In Bat File



## Slimboy Fat (Oct 29, 2004)

Hello,

Using code found in the closed thread at http://forums.techguy.org/dos-other/323716-append-date-filename-dos.html

The following part of code should be giving the current date as YYYYMMDD but I am only getting MMYYYY

I am running this on Server 2012 operating system.

for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set yyyymmdd=%%k%%i%%j
echo Date: %yyyymmdd%

TIA
SBF


----------



## foxidrive (Oct 20, 2012)

It's because the format of the system date can be changed by the user and also changes in different regions in the world.

Use this if you can:

The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.


```
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%" & set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
echo datestamp: "%datestamp%"
echo timestamp: "%timestamp%"
echo fullstamp: "%fullstamp%"
pause
```


----------



## Slimboy Fat (Oct 29, 2004)

Thanks foxidrive,

This worked perfect and the code is easier to understand for a novice like me 

Thank you
Slimboy Fat


----------

