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


NOTE: See 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
set $TDYMD$="%temp%\TDYMD_%RANDOM%.vbs"
echo D = Now : WScript.Echo Year(D) ^& " " ^& Right(100+Month(D),2) ^& " " ^& Right(100+Day(D),2) >%$TDYMD$%
for /f "tokens=1-3" %%x in ('cscript.exe //Nologo %$TDYMD$%') do (
 set %1=%%x
 set %2=%%y
 set %3=%%z
)
del /q %$TDYMD$%
set $TDYMD$=



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