Computing.Net > Forums > Windows 2000 > DATE string for a directory in DOS

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DATE string for a directory in DOS

Reply to Message Icon

Name: Marc
Date: August 27, 2002 at 18:02:54 Pacific
Comment:

Funny but on Unix for me this is a snap. However, I'm on Win 2K Prof and need to dynamically create a directory with todays date. I'll need it DOS compatible so something like MMDDYYYY will work (e.g. 08272002). Any ideas. I'm clueless about VB and really don't want to install PERL just for this tiny task. However, I need the functionality for some dynamic reporting.



Sponsored Link
Ads by Google

Response Number 1
Name: Tom
Date: August 28, 2002 at 08:25:20 Pacific
Reply:

Paste this script into a .bat file, and that should do the trick.

:: Works on any NT machine independent of regional date settings

@ECHO off
SETLOCAL
IF [%1]==[] goto s_start

ECHO GETDATE.cmd
ECHO Returns the date independent of regional settings
ECHO Creates the environment variables %v_year% %v_month% %v_day%
ECHO.
ECHO SYNTAX
ECHO GETDATE
ECHO.
ECHO.
GOTO :eof

:s_start

FOR /f "tokens=2-4 skip=1 delims=(-)" %%G IN ('echo.^|date') DO (
FOR /f "tokens=2 delims= " %%A IN ('date /t') DO (
SET v_first=%%G
SET v_second=%%H
SET v_third=%%I
SET v_all=%%A
)
)

SET %v_first%=%v_all:~0,2%
SET %v_second%=%v_all:~3,2%
SET %v_third%=%v_all:~6,4%

::ECHO Today is Year: [%yy%] Month: [%mm%] Day: [%dd%]

SET v_year=%yy%& SET v_month=%mm%& SET v_day=%dd%

SET todaysdirectory=%v_month%%v_day%%v_year%

ECHO Creating Directory %todaysdirectory%

md %todaysdirectory%


0
Reply to Message Icon

Related Posts

See More


Dial up networking Win2k video driver proble...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows 2000 Forum Home


Sponsored links

Ads by Google


Results for: DATE string for a directory in DOS

Help renaming a file in DOS www.computing.net/answers/windows-2000/help-renaming-a-file-in-dos/62171.html

Window refresh delays in DOS applic www.computing.net/answers/windows-2000/window-refresh-delays-in-dos-applic/45249.html

Printing on a network in Dos www.computing.net/answers/windows-2000/printing-on-a-network-in-dos/46242.html