Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for sortdate.bat

(view source code of sortdate.bat as plain text)

  1. @ECHO OFF
  2. IF NOT "%1"=="" GOTO Syntax
  3.  
  4. :: Use BATCHMAN to retrieve day
  5. BATCHMAN DAY
  6. :: Errorlevel 0 means BATCHMAN was not found
  7. IF NOT ERRORLEVEL 1 GOTO NotFound
  8. FOR %%A IN   (1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL  %%A SET DD=0%%A
  9. FOR %%A IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL 1%%A SET DD=1%%A
  10. FOR %%A IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL 2%%A SET DD=2%%A
  11. FOR %%A IN (0 1)                 DO IF ERRORLEVEL 3%%A SET DD=3%%A
  12.  
  13. :: Use BATCHMAN to retrieve month
  14. BATCHMAN MONTH
  15. FOR %%A IN (1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL  %%A SET MM=0%%A
  16. FOR %%A IN (0 1 2)             DO IF ERRORLEVEL 1%%A SET MM=1%%A
  17.  
  18. :: Use BATCHMAN to retrieve year
  19. BATCHMAN YEAR
  20. FOR %%A IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL  %%A SET YYYY=198%%A
  21. FOR %%A IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL 1%%A SET YYYY=199%%A
  22. FOR %%A IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL 2%%A SET YYYY=200%%A
  23. FOR %%A IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL 3%%A SET YYYY=201%%A
  24.  
  25. :: Store in variable and clean up temporary variables
  26. SET SortDate=%YYYY%%MM%%DD%
  27. SET YYYY=
  28. SET MM=
  29. SET DD=
  30.  
  31. :: Display the result
  32. ECHO.
  33. ECHO SortDate = %SortDate%
  34. GOTO End
  35.  
  36. :Syntax
  37. ECHO.
  38. ECHO SortDate.bat,  Version 1.00 for MS-DOS
  39. ECHO Display the current date in YYYYMMDD format
  40. ECHO.
  41. ECHO Usage:  SORTDATE
  42. ECHO.
  43. ECHO This batch file uses BATCHMAN, a utility by Michael Mefford
  44. ECHO.
  45. ECHO Written by Rob van der Woude
  46. ECHO http://www.robvanderwoude.com
  47.  
  48. :End
  49.  

page last modified: 2024-04-16; loaded in 0.0064 seconds