• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

WINXP SP3 DOS prompt make directory

Hi,

i using winxp sp3 's dos environment  , want to made sub-directory accroding to YYYYMMDD

here is command using at winsp2, new change to winxp sp3 environment , it seems not work :

md Y:\FoxproserverBackup\%date:~0,4%%date:~5,2%%date:~8,2%

what happened ?



Stanley
0
candychan611
Asked:
candychan611
  • 3
  • 2
1 Solution
 
oBdACommented:
Probably a new profile with new date format settings.
If the former command worked, you used a date format like YYYY/MM/DD (or some other separator than "/").
Check the output of
echo %date%

Open in new window

in a command prompt. You can then create the time stamp to your likings; the first of the two numbers after "%date:~" is the zero-based start index of the string you want to extract, the second one the number of characters, then follows the closing "%".
So if your date shows up as "04/14/2014", you'd use %date:~6,4%%date:~0,2%%date:~3,2% to get the YYYYMMDD format.
Or you can use a batch script that runs a WMI query, which doesn't depend on the date format:
@echo off
setlocal enabledelayedexpansion
set /a Line=0
for /f "tokens=1-9" %%a in ('wmic.exe Path Win32_LocalTime Get Day^,DayOfWeek^,Hour^,Minute^,Month^,Quarter^,Second^,WeekInMonth^,Year ^| find /v ""') do (
  set /a Line += 1
  if "!Line!"=="1" (set VarA=%%a&set VarB=%%b&set VarC=%%c&set VarD=%%d&set VarE=%%e&set VarF=%%f&set VarG=%%g&set VarH=%%h&set VarI=%%i)
  if "!Line!"=="2" (set !VarA!=%%a&set !VarB!=%%b&set !VarC!=%%c&set !VarD!=%%d&set !VarE!=%%e&set !VarF!=%%f&set !VarG!=%%g&set !VarH!=%%h&set !VarI!=%%i)
)
for %%a in (Month Day Hour Minute Second) do (if !%%a! LSS 10 set %%a=0!%%a!)
REM *** At this point, the variables Day, DayOfWeek, Hour, Minute, Month, Quarter, Second, WeekInMonth, and Year are set.
REM *** Month, Day, Hour, Minute, Second have leading zeros if less than 10.
set TimeStamp=%Year%%Month%%Day%
md Y:\FoxproserverBackup\%Timestamp%

Open in new window

0
 
candychan611Author Commented:
Hi oBDA,

Let me try    "%date:~6,4%%date:~0,2%%date:~3,2%" format  at  office tomorrow.

Can you provide some   reference book/site for the new syntax ?


Stanley
0
 
oBdACommented:
It's not a new syntax, it's the definition of the date format, which is user dependent.
%Date% will have the format defined in "Short date" in Control Panel -> Region.
0
 
candychan611Author Commented:
oh ic ic
0
 
candychan611Author Commented:
The  XP SP3  regional setting is Hong Kong ,  

but  XP SP2 should be regional --- Taiwan .

So i will change to "Taiwan"  and  use the old  command:
md Y:\FoxproserverBackup\%date:~0,4%%date:~5,2%%date:~8,2%


Thanks for your help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now