Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Date and time format from a batch file

15 views
Skip to first unread message

bjga...@gmail.com

unread,
Sep 14, 2005, 1:43:48 PM9/14/05
to
Ive been tring to figure out a way to re-format the output of date
"c:/date /t" from "Wed 09/14/2005" to 09142005. Anythought on how to do
this in windows 2000 would be very helpful.

William Allen

unread,
Sep 14, 2005, 2:24:52 PM9/14/05
to
<bjga...@gmail.com> wrote in message

> Ive been tring to figure out a way to re-format the output of date
> "c:/date /t" from "Wed 09/14/2005" to 09142005. Anythought on how to do
> this in windows 2000 would be very helpful.

Read the /? help for the FOR command, which explains how to
extract tokens from strings. Typical syntax:

Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
SETLOCAL
FOR /f "tokens=2-4 delims=/ " %%A IN ("%DATE%") DO SET DT=%%A%%B%%C
ECHO. Date=%DT%

====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects

--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com/


Dr John Stockton

unread,
Sep 15, 2005, 9:02:54 AM9/15/05
to
JRS: In article <1126719828....@o13g2000cwo.googlegroups.com>,
dated Wed, 14 Sep 2005 10:43:48, seen in news:alt.msdos.batch.nt,
bjga...@gmail.com posted :

>Ive been tring to figure out a way to re-format the output of date
>"c:/date /t" from "Wed 09/14/2005" to 09142005. Anythought on how to do
>this in windows 2000 would be very helpful.

Well, you could pipe it through mtr -o \D+ = ""
where mtr is MiniTrue; not worth installing for the one job, of course;
but worth having in general.

But it would be far better to go for 20050914 - not only is that in
accordance with ISO 8601, but it also accords with a FIPS, and is
manifestly better.

To get the date output in that format, you can use

NOWMINUS f1 j0 r ; software date, as is proper
NOWMINUS ^ f1 j0 r ; software date, as WA prefers !!!

getting NOWMINUS.ZIP from <URL:http://www.merlyn.demon.co.uk/programs/>;
NOWMINUS enables various manipulations and formats of the date (e.g.
last Thursday, as year-quarter-day).

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
I find MiniTrue useful for viewing/searching/altering files, at a DOS prompt;
free, DOS/Win/UNIX, <URL:http://www.idiotsdelight.net/minitrue/>

Brian

unread,
Sep 15, 2005, 9:41:39 PM9/15/05
to
good point on the ISO date.

Thanks, Brian

0 new messages