Q. How can I convert a year, month, and day to my short date format?

I have scripted YMD2SD.bat to convert a year, month, and day to my short date format.

The syntax for using YMD2SD.bat is:

\[call\] YMD2SD Year, Month, Day, ShortDate


Year      is the year.

Month     is the month. If Month is greater than 12, Year will be adjusted.

Day       is the day. If Day exceeds the allowable value for Month, Month will be adjusted. 

ShortDate is a call directed environment variable that will contain the year, month, and day 
          in your short date format.
YMD2SD.bat contains:
@echo off
if \{%4\}==\{\} @echo Syntax: YMD2SD Year, Month, Day, ShortDate&goto :EOF
if exist "%TEMP%\YMD2SD.vbs" goto doit
@echo set objArguments = Wscript.Arguments>"%TEMP%\YMD2SD.vbs"
@echo WScript.Echo DateSerial(objArguments(0), objArguments(1), objArguments(2))>>"%TEMP%\YMD2SD.vbs"
for /f "Tokens=*" %%d in ('cscript //nologo "%TEMP%\YMD2SD.vbs" %1 %2 %3') do (
 set %4=%%d

Hide 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.