JSI Tip 10485. A better way to return today's 4 digit year, 2 digit month, and 2 digit day, regardless of your date format.


The are a number of ways to return today's date to a script:

Today.bat    - Good for both calculations and setting file names.
UnivDate.bat - Use with YYYYMMDD.bat to set file names.
NOTE: For calculations, use:
JSIDateM.bat - General purpose date math routine.
DatePorM.bat - How can I return the date that is plus or minus n days from today?
I have scripted TDYMD.bat to return today's 4 digit year, 2 digit month, and 2 digit day, regardless of your date format.

TDYMD.bat is optimized for setting file names.

The syntax for using TDYMD.bat is:

call TDYMD YYYY MM DD

Where:

YYYY  is a call directed environment variable that will contain today's 4 digit year.
MM    is a call directed environment variable that will contain today's 2 digit month.
DD    is a call directed environment variable that will contain today's 2 digit day.
TDYMD.bat contains:
@echo off
if \{%3\}==\{\} @echo Syntax :TDYMD YYYY MM DD&goto :EOF
if not exist "%TEMP%\TDYMD.VBS" @echo Wscript.Echo Year(Now()) ^& " " ^& Right("0" ^& Month(Now()),2) ^& " " ^& Right("0" ^& Day(Now()),2)>"%TEMP%\TDYMD.VBS"
for /f "tokens=1-3" %%x in ('cscript.exe //Nologo "%TEMP%\TDYMD.VBS"') do (
 set %1=%%x
 set %2=%%y
 set %3=%%z
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish