Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for sortdate5.bat

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

  1. @ECHO OFF
  2. ECHO.
  3.  
  4. :: Check Windows version (XP Pro or later) and command line arguments (none)
  5. IF NOT "%OS%"=="Windows_NT"    GOTO Syntax
  6. IF NOT "%~1"==""               GOTO Syntax
  7. WMIC.EXE Alias /? >NUL 2>&1 || GOTO Syntax
  8.  
  9. SETLOCAL ENABLEDELAYEDEXPANSION
  10.  
  11. :: Use WMIC to retrieve date and time
  12. FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO (
  13. 	IF NOT "%%~F"=="" (
  14. 		SET /A SortDate = 10000 * %%F + 100 * %%D + %%A
  15. 		SET /A SortTime = 10000 * %%B + 100 * %%C + %%E
  16. 		SET SortTime=0000000!SortTime!
  17. 		SET SortTime=!SortTime:~-6!
  18. 	)
  19. )
  20.  
  21. :: Display the results:
  22. SET Sort
  23.  
  24. :: Done
  25. ENDLOCAL
  26. GOTO:EOF
  27.  
  28.  
  29. :Syntax
  30. ECHO SortDate.bat, Version 5.01 for Windows XP Pro and later
  31. ECHO Displays date and time in YYYYMMDD and HHmmSS format,
  32. ECHO completely independent of Windows' Regional Settings or
  33. ECHO language, and without the use of temporary files.
  34. ECHO.
  35. ECHO Usage:  SORTDATE
  36. ECHO.
  37. ECHO Note:   Uses WMIC to query the current date and time;
  38. ECHO         WMIC is native in Windows XP Professional,
  39. ECHO         Windows Server 2003 and Windows Vista.
  40. ECHO.
  41. ECHO Written by Rob van der Woude
  42. ECHO http://www.robvanderwoude.com
  43. ECHO.
  44.  

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