Skip navigation

JSI Tip 8600. Today.bat returns today's numeric month, day, and year, the 3 character month abbreviation, and the 2 digit month and day.


In tip 4835, I parsed today's date for any NT-based operating system.

In tip 6837, I returned the 3 character abbreviation for the current month.

I have scripted Today.bat to return today's numeric month, day, and year, the 3 character month abbreviation, and the 2 digit month and day.

The syntax for using Today.bat is:

call today MMn DDn YYn Abrev MM DD

Where:

MMn   is a call directed numeric environment variable that will contain today's month.
DDn   is a call directed numeric environment variable that will contain today's day.
YYn   is a call directed numeric environment variable that will contain today's 4 digit year.
Abrev is a call directed environment variable that will contain today's 3 character month abbreviation.
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.

Example:

If today was January 3, 2005, then call today MMn DDn YYn Abrev MM DD would set:
MMn   to 1
DDn   to 3
YYn   to 2005
Abrev to Jan
MM    to 01
DD    to 03
Today.bat contains:
@echo off
if \{%6\}==\{\} @echo Syntax: Today MMn DDn YYn Abrev MM DD&goto :EOF
setlocal
set vb="%temp%\today_%RANDOM%.vbs"
echo D = Now : MN = MonthName(Month(D), True)  >%vb%
echo WScript.Echo MN ^& " " ^& Month(D) ^& " " ^& Day(D) ^& " " ^& Year(D) >>%vb%
for /f "tokens=1-4" %%a in ('cscript.exe //Nologo %vb%') do (
 set abrev=%%a
 set /a MMn=100%%b%%100
 set /a DDn=100%%c%%100
 set /a YYn=10000%%d%%10000
)
del /q %vb%
if %YYn% LSS 1000 set /a YYn=%YYn% + 2000
set /a MM=%MMn%
set /a DD=%DDn%
if %MM% LSS 10 set MM=0%MM%
if %DD% LSS 10 set DD=0%DD%
endlocal&set %1=%MMn%&set %2=%DDn%&set %3=%YYn%&set %4=%abrev%&set %5=%MM%&set %6=%DD%



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