"David" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> I believe it is a problem with the Command Extensions - ie. my batch
> file is using them, and they are not enabled. I get the following
> errors :
You can turn them on by adding 'setlocal ENABLEEXTENSIONS' to your
batch file, something like:-
@echo off & setlocal ENABLEEXTENSIONS
The method you're currently using to load date and time components into
variables is highly reliant the regional settings and delimiters used.
This is definitely not a good idea especially if the script is to run
on other machines. Here's a more reliable way (but I'm not your dad <g>)
01. @echo off & setlocal ENABLEEXTENSIONS
02. call :GetTime h n s t
03. call :GetDate y d m
04. echo/Today is: %y%-%m%-%d% %h%:%n%:%s%
05. goto :EOF
06.
07. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
08. :GetTime hh nn ss tt
09. ::
10. :: By: Ritchie Lawrence, updated 2002-10-30. Version 1.2
11. ::
12. :: Func: Loads local system time components into args 1 to 4.
13. :: For NT4/2K/XP/2003
14. ::
15. :: Args: %1 Var to receive hours, 2 digits, 00 to 23 (by ref)
16. :: %2 Var to receive minutes, 2 digits, 00 to 59 (by ref)
17. :: %3 Var to receive seconds, 2 digits, 00 to 59 (by ref)
18. :: %4 Var to receive centiseconds, 2 digits, 00 to 99 (by ref)
19. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
20. setlocal ENABLEEXTENSIONS
21. for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
22. set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d)
23. if 1%hh% LSS 20 set hh=0%hh%
24. endlocal&set %1=%hh%&set %2=%nn%&set %3=%ss%&set %4=%cs%&goto :EOF
25. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
26.
27. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
28. :GetDate yy mm dd
29. ::
30. :: By: Ritchie Lawrence, 2002-06-15. Version 1.0
31. ::
32. :: Func: Loads local system date components into args 1 to 3.
33. :: For NT4/2000/XP/2003.
34. ::
35. :: Args: %1 var to receive year, 4 digits (by ref)
36. :: %2 var to receive month, 2 digits, 01 to 12 (by ref)
37. :: %3 Var to receive day of month, 2 digits, 01 to 31 (by ref)
38. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
39. setlocal ENABLEEXTENSIONS
40. set t=2&if "%date%z" LSS "A" set t=1
41. for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
42. for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
43. set %%a=%%d&set %%b=%%e&set %%c=%%f))
44. endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
45. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--
Ritchie, undo for mail
|