ADSM-L

Re: DATE IN DOS

2000-09-27 18:16:40
Subject: Re: DATE IN DOS
From: Andy Raibeck <Andrew_Raibeck AT TIVOLI DOT COM>
Date: Wed, 27 Sep 2000 15:15:27 -0700
When you say DOS, I am guessing you mean the Windows command line?

I am not an expert on these advanced features, but from Windows
2000 you can do this:

   set MYDATE=%date%

To see what MYDATE is, do one of these:

   echo %MYDATE%
   set MYDATE
   set M     (or any first n characters in the name "MYDATE")

You will see that MYDATE is:

   Wed 09/27/2000

If you want only the mm/dd/yyyy portion, you can do this:

   for /f "tokens=2-4 delims=/ " %r in ('date /t') do echo %r %s %t

When using in a script, you need to put two '%' signs in front of
the variable, like this:

   for /f "tokens=2-4 delims=/ " %%r in ('date /t') do echo %%r %%s %%t

Here is a sample script that shows how you can use this:

================================================
   @echo off
   setlocal

   for /f "tokens=2-4 delims=/ " %%r in ('date /t') do set MM=%%r& set DD=%%s& 
set YYYY=%%t

   echo Month='%MM%'
   echo Day='%DD%'
   echo Year='%YYYY%'

   set DMY=%DD%/%MM%/%YYYY%
   set YMD=%YYYY%/%MM%/%DD%
   set MDY=%MM%/%DD%/%YYYY%

   echo Date in yyyy/mm/dd = '%YMD%'
   echo Date in dd/mm/yyyy = '%DMY%'
   echo DATE in mm/dd/yyyy = '%MDY%'

   endlocal
================================================

Obviously the heart of this is in the "for" statement. You can type
"for /?" from the command line for help, or use the GUI help for
the OS.

As I said, this works on 2000. It will also probably work on NT 4.0.
However, Win9x does not support these "advanced" scripting features,
so if you need it there, you need to try an alternative.

You might consider going with a more powerful scripting tool. REXX is
a very flexible language. Also, there's the new host scripting
feature available for Windows 95, 98, NT and 2000 that might offer
a good alternative to the standard command-line scripting tool.

Regards,

Andy

Andy Raibeck
IBM/Tivoli
Tivoli Storage Manager Client Development
e-mail: andrew.raibeck AT tivoli DOT com
"The only dumb question is the one that goes unasked."


I'm designing a batch file in DOS  for restore some files backed up on
current date.  I don´t know how obtain current date from DOS and assign it
to a variable.  Any idea?

Thanks in advance.


Raul Giraldo Suarez
TSM  Bancolombia.
<Prev in Thread] Current Thread [Next in Thread>