Problem with year in a batch file

September 8, 2011 at 10:20:03
Specs: Windows XP
Why when i run something like this in a batch file
SET backuptime=%DATE:~4%
echo %backuptime%
echo Done!

I receive 09/2011
Done!

I need only the 4 digits from actual year, but i don't how to do it.
Thansk for your time and attention


See More: Problem with year in a batch file

Report •

#1
September 8, 2011 at 16:23:17
try this:

@echo off
set backuptime=%date:~10,4%
echo %backuptime%
echo done!

hope it helps


Report •

#2
September 8, 2011 at 21:07:21
Finally, after some hours reading around the web i could make it. I did it in this way.

for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set dia=%%a& set mes=%%b& set año=%%c)
SET backuptime=%año%
echo %backuptime%

It works as i need it.

Thanks a lot for your support crashnburn99


Report •

#3
September 8, 2011 at 23:25:32
You could just use;

set backuptime=%date:~-4%
echo %backuptime%
pause

Regards,

Happy is ONE who says I am an OttoMAN.


Report •

Related Solutions

#4
September 9, 2011 at 08:39:57
Not a problem. Glad you found a fix.

Report •

Ask Question