Skip navigation

Q. How can I convert a short date to a long date?

I have scripted LongDate.bat to return the long date format for a given short date.

The syntax for using LongDate.bat is:

\[call\] LongDate sDate lDate

Where:

sDate is a short date, in your short date format, like 10/03/2006.

lDate is a call directed environment variable that will contain the long date format for sDate, like Tuesday, October 03, 2006.

NOTE: If sDate is not valid, lDate will contain Sunday, December 31, 1600.

LongDate.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: LongDate sDate lDate&goto :EOF
if exist "%TEMP%\LongDate.vbs" goto doit
@echo.set objArguments = Wscript.Arguments>"%TEMP%\LongDate.vbs"
@echo sDate = cDate(objArguments(0))>>"%TEMP%\LongDate.vbs"
@echo.Wscript.Echo FormatDateTime(sDate, 1)>>"%TEMP%\LongDate.vbs"
:doit
set %2=Sunday, December 31, 1600
call :quiet %1 %2>nul 2>&1
goto :EOF
:quiet
for /f "Tokens=*" %%d in ('cscript //nologo "%TEMP%\LongDate.vbs" %1') do (
 set %2=%%d
)


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