Solved

How do I use tokens in a batch file to get the date

Posted on 2007-11-23
3
2,431 Views
Last Modified: 2010-04-21
I need some help to understand and modify this batch file that I found here on EE:

:: --------TODAY.BAT----------
:: @ECHO OFF
FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (SET TODAY=%%H%%F%%G)
dir * > %TODAY%.txt
:: --------TODAY.BAT----------

This will produce TODAY to be YYYYMMDD.
What I NEED is YYMMDD. How do I get this?

And, where can I learn the details on what the variables are and how this works? ( I looked around a bit but never found what I am looking for),
0
Comment
Question by:dbrennecke
3 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20337802
download a tiny, free command line utility called fdate. search google for "fdate"
0
 
LVL 7

Accepted Solution

by:
djMundy earned 125 total points
ID: 20337809
Hi dbrennecke,

I'm not sure if this is the most elegant way but it works:

:: --------TODAY.BAT----------
:: @ECHO OFF
FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (SET TODAY=%%H%%F%%G)
SET TODAY=%TODAY:~-6%
dir * > %TODAY%.txt
:: --------TODAY.BAT----------

Cheers,
Daniel
0
 

Author Closing Comment

by:dbrennecke
ID: 31410640
Works for me!   Thanks.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Can you find a fax from a vendor you saved a decade ago in seconds? Have you ever cursed your PC under your breath during an audit because you couldn’t find the requested statement or driver history?  If you answered no to the first question or yes …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question