Here are some alternative ideas.
The following example uses a For
loop and delayed expansion to parse the months:
@Echo Off
SetLocal EnableDelayedExpansion
For %%A In (Long Short) Do Set "%%ADate="
Set /P "ShortDate=Please enter the date in short date format [MMMyy]: "
For %%A In (January February March April May June July August September October
November December) Do (Set "LongMonth=%%A"
If /I "%ShortDate:~,3%"=="!LongMonth:~,3!" (
Set "LongDate=%%A20%ShortDate:~-2%"))
If Defined LongDate Echo %LongDate%
Pause
…and this uses key pairs with variable expansion and replacement:
@Echo Off
Set "kp=Jan-January;Feb-February;Mar-March;Apr-April;May-May;Jun-June;Jul-July"
Set "kp=%kp%;Aug-August;Sep-September;Oct-October;Nov-November;Dec-December"
Set /P "ShortDate=Please enter the date in short date format [MMMyy]: "
Call Set "LongMonth=%%kp:*%ShortDate:~,3%-=%%"
Set "LongMonth=%LongMonth:;="&:"%"
Set "LongYear=20%ShortDate:~-2%"
Set "LongDate=%LongMonth%%LongYear%"
Echo=%LongDate%
Pause
…and the following example gets help from PowerShell:
@Echo Off
Set "SDF=MMMyy"
Set "LDF=MMMMyyyy"
For %%A In (L S) Do Set "%%AD="
Set /P "SD=Please enter the date in short date format [MMMyy]: "
For /F UseBackQ %%A In (`PowerShell^
"([datetime]::ParseExact('%SD%','%SDF%', [System.Globalization.CultureInfo]::CurrentCulture)).ToString('%LDF%')"
`) Do Set "LD=%%A"
If Defined LD Echo %LD%
Pause