Need help in date format

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Need help in date format

#1 Post by lalat06bag » 19 Apr 2018 19:19

Hi,

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%a%%b)

Here mydate gives 2018419 which is YYYYMMDD format.

I want the date format in YYMMDD. Please see, if this is possible in the above code.

I tried below and it works.
Set mydate=%date:~-2%%date:~4,2%%date:~7,2%
This gives the format YYMMDD which I want. Just looking for the above one, if can give YYMMDD.


Thank you!

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Need help in date format

#2 Post by SIMMS7400 » 20 Apr 2018 04:54

Code: Select all

echo %date:~-2,4%%date:~-10,2%%date:~-7,2%
pause
If you want timestamp to, especially if you run this more than once per day:

Code: Select all

FOR /F "tokens=1-2 delims=/:" %%A IN ("%TIME%")   DO ( SET TIMESTAMP=%%A%%B)
FOR /F "tokens=* delims= " %%C IN ("%TIMESTAMP%") DO ( SET TIMESTAMP=%%C)
SET "DATETIME=%date:~-2,4%%date:~-10,2%%date:~-7,2%_%TIMESTAMP%"

echo %DATETIME%
pause

lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Re: Need help in date format

#3 Post by lalat06bag » 20 Apr 2018 06:38

Thank you

Post Reply