1.

Solve : Date format in DD/Month/YYYY?

Answer»

Dear All,

I am a fresher in writing batch file, I HAC requirment where i need to display date in the formate of DD/Month/YYYY.

I searched in google for peace of CODE.

I got this
------------------------------------------------------------------------
@echo off&SETLOCAL

:: This will return date into environment vars
:: Works on any NT/2K/XP machine independent of REGIONAL date settings
:: 20 March 2002

FOR /F "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :s_fixdate %%G %%H %%I %%J)
goto :s_print_the_date

:s_fixdate
if "%1:~0,1%" GTR "9" shift
FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^|date') DO (
set %%G=%1&set %%H=%2&set %%I=%3)
goto :eof

:s_print_the_date
echo Month:[%MM%] Day:[%dd%] Year:[%YY%]
ENDLOCAL&SET mm=%mm%&SET dd=%dd%&SET yy=%yy%
-----------------------------------------------------------------------

The above code will print in the format 12 19 2005

What i want is December 19 2005

Thanks for your help.

Regards,
Satya.the batch uses "date" command. somehow the date command has no option to display long date format. (somebody else can advise on this) .
The closest command that can display the date with the word "December" is the "now" command from the resource kit. On my machine it displays "Mon Dec 19 11:23:54 2005" . Though it only displays "Dec". Use a for loop inside your batch to get the "Dec"

Otherwise you could use a better programming langauge such as Perl to do the job. This is only a suggestion.This is how I format the date, maybe hoaky but it works.

@echo off
START /W REGEDIT /E %TEMP%.\GETDATE.REG "HKEY_CURRENT_USER\Control Panel\International"
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\GETDATE.REG ^| FIND /I "iDate"') DO SET iDate=%%B
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\GETDATE.REG ^| FIND /I "sDate"') DO SET sDate=%%B
DEL %TEMP%.\GETDATE.REG
SET iDate=%iDate:"=%
SET sDate=%sDate:"=%
IF %iDate%==0 FOR /F "TOKENS=1-4* DELIMS=%sDate% " %%A IN ('DATE/T') DO (
SET Year=%%D
SET Month=%%B
SET Day=%%C
)
IF %iDate%==1 FOR /F "TOKENS=1-4* DELIMS=%sDate% " %%A IN ('DATE/T') DO (
SET Year=%%D
SET Month=%%C
SET Day=%%B
)
IF %iDate%==2 FOR /F "TOKENS=1-4* DELIMS=%sDate% " %%A IN ('DATE/T') DO (
SET Year=%%B
SET Month=%%C
SET Day=%%D
)

IF "%Month%" == "1" set month=January
IF "%Month%" == "2" set month=February
IF "%Month%" == "3" set month=March
IF "%Month%" == "4" set month=April
IF "%Month%" == "5" set month=May
IF "%Month%" == "6" set month=June
IF "%Month%" == "7" set month=July
IF "%Month%" == "8" set month=August
IF "%Month%" == "9" set month=September
IF "%Month%" == "10" set month=October
IF "%Month%" == "11" set month=November
IF "%Month%" == "12" set month=December

SET FORMATDATE=%Month% %Day% %Year%
echo %FORMATDATE%
echo Hit enter to continue
set /p=



Discussion

No Comment Found