JSI Tip 10272. Another way to return a 4 digit year, 2 digit month, and 2 digit day from a short date, regardless of your short date format.


I had previously scripted sDate.bat as Another way to return a 4 digit year, 2 digit month, and 2 digit day from a short date, regardless of your short date format.

Date2YMD.bat is a faster method, that does NOT require the script to explicitly access the registry.

The syntax for using Date2YMD.bat is:

call Date2YMD ShortDate Year Month Day

Where:

ShortDate is the short date that you wish to enumerate.
Year      is a call directed environment variable that will contain ShortDate's 4 digit year.
Month     is a call directed environment variable that will contain ShortDate's 2 digit month.
Day       is a call directed environment variable that will contain ShortDate's 2 digit day.
Date2YMD.bat contains:
@echo off
if \{%4\}==\{\} @echo Syntax: Date2YMD ShortDate Year Month Day&goto :EOF
if exist "%TEMP%\Date2YMD.vbs" goto :doit
@echo Dim Arguments, sd>"%TEMP%\Date2YMD.vbs"
@echo Set Arguments = Wscript.Arguments>>"%TEMP%\Date2YMD.vbs"
@echo sd = Arguments(0)>>"%TEMP%\Date2YMD.vbs"
@echo yyyy = DatePart("yyyy", sd)>>"%TEMP%\Date2YMD.vbs"
@echo m = Right(100+DatePart("m", sd),2)>>"%TEMP%\Date2YMD.vbs"
@echo d = Right(100+DatePart("d", sd),2)>>"%TEMP%\Date2YMD.vbs"
@echo Wscript.Echo yyyy ^& " " ^& m ^& " " ^& d>>"%TEMP%\Date2YMD.vbs"
:doit
for /f "Tokens=1-3" %%a in ('cscript //nologo "%TEMP%\Date2YMD.vbs" %1') do (
 set %2=%%a
 set %3=%%b
 set %4=%%c
) 
endlocal



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