I have a script which give me the current date
set ftpdate=%date:~4,2%%date:~7,2%%date:~-2%.txt
echo %ftpdate%
Need help to modify the script to give the pervious days date.
Ajay
Convert todays date to a number, subtract one, then convert back to
a date (thats how I'd do it anyway). Here's an example:-
01. @echo off & setlocal ENABLEEXTENSIONS
02. call :GetDate yy mm dd
03. call :DateToDays %yy% %mm% %dd% days
04. set /a days-=1
05. call :DaysToDate %days% yy mm dd
06. echo/Yesterdays date: %yy%-%mm%-%dd%
07. goto :EOF
08.
09. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
10. :GetDate yy mm dd
11. ::
12. :: By: Ritchie Lawrence, 2002-06-15. Version 1.0
13. ::
14. :: Func: Loads system date components into args 1 to 3. For NT4/2K/XP
15. ::
16. :: Args: %1 var to receive year, 4 digits (by ref)
17. :: %2 var to receive month, 2 digits, 01 to 12 (by ref)
18. :: %3 Var to receive day of month, 2 digits, 01 to 31 (by ref)
19. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
20. setlocal ENABLEEXTENSIONS
21. set t=2&if "%date%z" LSS "A" set t=1
22. for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
23. for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
24. set %%a=%%d&set %%b=%%e&set %%c=%%f))
25. endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
26. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
27.
28. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
29. :DateToDays %yy% %mm% %dd% days
30. ::
31. :: By: Ritchie Lawrence, 2002-09-26. Version 1.0
32. ::
33. :: Func: Returns the number of days elapsed since 1st January 1970 for a
34. :: given date. For NT4/2K/XP
35. ::
36. :: Args: %1 year component used to create days, 2 or 4 digits (by val)
37. :: %2 month component used to create days, leading zero ok (by val)
38. :: %3 date of month used to create days, leading zero ok (by val)
39. :: %4 var to receive number of elapsed days (by ref)
40. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
41. setlocal ENABLEEXTENSIONS
42. set yy=%1&set mm=%2&set dd=%3
43. if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
44. set /a dd=100%dd%%%100,mm=100%mm%%%100
45. set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
46. set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
47. endlocal&set %4=%j%&goto :EOF
48. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
49.
50. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
51. :DaysToDate %days% yy mm dd
52. ::
53. :: By: Ritchie Lawrence, 2002-06-15. Version 1.1
54. ::
55. :: Func: Returns a calendar date from the number of elapsed days since 1st
56. :: January 1970 UTC. For NT4/2K/XP.
57. ::
58. :: Args: %1 MJD used to create calendar date (by val)
59. :: %2 var to receive year component, 4 digits (by ref)
60. :: %3 var to receive month component, 2 digits, 01-12 (by ref)
61. :: %4 var to receive day of month component, 2 digits, 01-31 (by ref)
62. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
63. setlocal ENABLEEXTENSIONS
64. set /a a=%1+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
65. set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
66. set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
67. (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
68. endlocal&set %2=%yy%&set %3=%mm%&set %4=%dd%&goto :EOF
69. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
You can de-number the example with the script in this post:-
http://groups.google.com/groups?threadm=3eb26737%241%24955%24cc9e4d1f%40news.dial.pipex.com.
--
Ritchie