1.

Solve : Batch file: getting only the last 2 digits of the year?

Answer»

Like in: for /f "tokens=1-4 delims=/ " %%d in ("%date%") do @echo %%f%%e%%d
but I want only the 09 out of 2009I dont think its possible anyone correct me If im wrongTry this code, the output is dependent on the date format returned by %date%. The input date format to this code is 'day mm/dd/yyyy' and the date is ECHOED in the format mmddyy:

Code: [Select]@echo off
cls
setlocal

for /f "tokens=1-4 delims=/ " %%a in ("%date%") do (
set bc=%%b%%c
set d=%%d

)

echo %bc%%d:~2%

you actually dont need all that code:

Code: [Select]@echo off
set digit=%DATE:~12,2%
echo %digit%
pause
but if you have a DIFFERENT date format, then let me KNOW(this one is DDD MM/DD/YYYY, e.g. Thu 03/11/2009)

Hope this Helps
,Nick(macdad-)I think they want DD/MM/YYQuote from: computeruler on March 11, 2009, 01:30:44 PM

I think they want DD/MM/YY

Hey! I've GOT this radical new idea! Let's have a look at the thread title and the original post!

Thread title

Quote
getting only the last 2 digits of the year

Original post

Quote
I want only the 09 out of 2009
Wow! that is radical!Radical or not it seems to me to be a better assumption that, based on the OP's script, the OP wants to return the date in either ddmmyy or mmddyy format.

Quote from: Woodman on March 11, 2009, 04:24:15 PM
Radical or not it seems to me to be a better assumption that, based on the OP's script, the OP wants to return the date in either ddmmyy or mmddyy format.



You may be right, I think I had the sarcsam dial turned to 10 or 11.
It's going to be 09 for about... Another like 280 days.

Echo '09'

Heck, I won't keep a batch file for a date for 1 year. Works for me.He's right. This must be for some other reason !Iunno if it works

Code: [Select]if %date%==*/*/2009 echo 09
IDK if it does.It doesn't work. It gives me the statement after if and says this wasn't expected.
It appears that you are trying to abuse the use of wild cards. They can not always
be used in such a manner.Or even:

if %date:~-4% gtr 2008 if %date:~-4% LSS 2010 echo %date:~-2%

Someone will put us out of our misery shortly...(code deleted)

since some people(s) might get offended if code create a .com executable. please accept my apology for any inconvenience caused.


Discussion

No Comment Found