Guest JohnB Posted June 30, 2008 Posted June 30, 2008 I know this isn't the DOS newsgroup but, I also know there are people here that can answer this. I need to create folder names based on the current date. The names need to be in this format: DDMMYY I've googled and found lots of examples, but none for that format. Anyone know how do do that? Thanks
Guest Pegasus \(MVP\) Posted June 30, 2008 Posted June 30, 2008 Re: Creating folder names "JohnB" <jbrigan@yahoo.com> wrote in message news:uwLCMzs2IHA.4920@TK2MSFTNGP05.phx.gbl... >I know this isn't the DOS newsgroup but, I also know there are people here >that can answer this. > > I need to create folder names based on the current date. The names need > to be in this format: DDMMYY > I've googled and found lots of examples, but none for that format. > Anyone know how do do that? > > Thanks DOS could never do this sort of thing but the Command Prompt under all Windows NT-based OSs can. The usual way is to rearrange the various elements of the %date% variable. Unfortunately this method often fails when used with different regional settings. The batch file below will always return the correct value in %MyDate%. 1. @echo off 2. echo>c:\TempVBS.vbs wscript.echo day(date()) * 10000 + month(date()) * 100 + right(year(date()),2) 3. for /F %%a in ('cscript //nologo c:\TempVBS.vbs') do set MyDate=%%a 4. echo Date=%MyDate%
Guest JohnB Posted June 30, 2008 Posted June 30, 2008 Re: Creating folder names After I posted that I found this solution: MD %date:~4,2%%date:~7,2%%date:~-2% It's simple and works perfect. but thanks anyway. "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message news:%23omCwJt2IHA.4848@TK2MSFTNGP05.phx.gbl... > > "JohnB" <jbrigan@yahoo.com> wrote in message > news:uwLCMzs2IHA.4920@TK2MSFTNGP05.phx.gbl... >>I know this isn't the DOS newsgroup but, I also know there are people here >>that can answer this. >> >> I need to create folder names based on the current date. The names need >> to be in this format: DDMMYY >> I've googled and found lots of examples, but none for that format. >> Anyone know how do do that? >> >> Thanks > > DOS could never do this sort of thing but the Command Prompt > under all Windows NT-based OSs can. The usual way is to > rearrange the various elements of the %date% variable. Unfortunately > this method often fails when used with different regional settings. > The batch file below will always return the correct value in %MyDate%. > 1. @echo off > 2. echo>c:\TempVBS.vbs wscript.echo day(date()) * 10000 + month(date()) * > 100 + right(year(date()),2) > 3. for /F %%a in ('cscript //nologo c:\TempVBS.vbs') do set MyDate=%%a > 4. echo Date=%MyDate% > >
Guest Pegasus \(MVP\) Posted June 30, 2008 Posted June 30, 2008 Re: Creating folder names "JohnB" <jbrigan@yahoo.com> wrote in message news:%231zF8mt2IHA.6096@TK2MSFTNGP06.phx.gbl... > After I posted that I found this solution: MD > %date:~4,2%%date:~7,2%%date:~-2% > > It's simple and works perfect. > > but thanks anyway. Yes, it works perfect until the order of digits changes. In some countries the variable %date% returns Mon 06/30/2008 whereas in others it returns Mon 30/06/2008. The nice and simple solution you found will trip over this difference.
Recommended Posts